diff --git a/chat/preview/CharacterPreview.vue b/chat/preview/CharacterPreview.vue index a80ddbc..1d23ef4 100644 --- a/chat/preview/CharacterPreview.vue +++ b/chat/preview/CharacterPreview.vue @@ -255,7 +255,7 @@ export default class CharacterPreview extends Vue { this.age = a.age ? this.readable(`${a.age}`) : (rawAge && /[0-9]/.test(rawAge.string || '') && rawAge.string) || undefined; this.species = a.species ? this.readable(Species[a.species]) : (rawSpecies && rawSpecies.string) || undefined; - this.gender = a.gender ? this.readable(Gender[a.gender]) : undefined; + this.gender = (a.gender && a.gender !== Gender.None) ? this.readable(Gender[a.gender]) : undefined; this.furryPref = a.furryPreference ? this.readable(furryPreferenceMapping[a.furryPreference]) : undefined; this.subDomRole = a.subDomRole ? this.readable(SubDomRole[a.subDomRole]) : undefined; this.sexualOrientation = a.orientation ? this.readable(Orientation[a.orientation]) : undefined; diff --git a/fchat/connection.ts b/fchat/connection.ts index a3646a3..2dd2790 100644 --- a/fchat/connection.ts +++ b/fchat/connection.ts @@ -184,6 +184,7 @@ export default class Connection implements Interfaces.Connection { 'api.query.start', { endpoint, + data, character: core.characters.ownCharacter?.name, deltaToLastApiCall: Date.now() - lastFetch, deltaToLastApiTicket: Date.now() - lastApiTicketFetch @@ -218,6 +219,7 @@ export default class Connection implements Interfaces.Connection { { error: res.error, endpoint, + data, character: core.characters.ownCharacter?.name, deltaToLastApiCall: Date.now() - lastFetch, deltaToLastApiTicket: Date.now() - lastApiTicketFetch @@ -233,6 +235,7 @@ export default class Connection implements Interfaces.Connection { 'api.query.success', { endpoint, + data, character: core.characters.ownCharacter?.name, deltaToLastApiCall: Date.now() - lastFetch, deltaToLastApiTicket: Date.now() - lastApiTicketFetch diff --git a/learn/cache-manager.ts b/learn/cache-manager.ts index ced4e5e..e1ac0fe 100644 --- a/learn/cache-manager.ts +++ b/learn/cache-manager.ts @@ -21,6 +21,8 @@ import { PermanentIndexedStore } from './store/types'; import * as path from 'path'; // import * as electron from 'electron'; +import log from 'electron-log'; //tslint:disable-line:match-default-export-name + export interface ProfileCacheQueueEntry { name: string; @@ -29,6 +31,7 @@ export interface ProfileCacheQueueEntry { gender?: Gender; score: number; channelId?: string; + retryCount: number; } @@ -53,6 +56,8 @@ export class CacheManager { protected lastFetch = Date.now(); + protected fetchLog: Record = {}; + protected ongoingLog: Record = {}; markLastPostTime(): void { this.lastPost = new Date(); @@ -67,6 +72,7 @@ export class CacheManager { return; } + log.info('profile.cache.queue', { name, skipCacheCheck, channelId }); if (!skipCacheCheck) { const c = await this.profileCache.get(name); @@ -87,7 +93,8 @@ export class CacheManager { key, channelId, added: new Date(), - score: 0 + score: 0, + retryCount: 0 }; this.queue.push(entry); @@ -102,7 +109,6 @@ export class CacheManager { await methods.fieldsGet(); const c = await methods.characterData(name, -1, true); - const r = await this.profileCache.register(c); this.updateAdScoringForProfile(c, r.match.matchScore); @@ -168,6 +174,11 @@ export class CacheManager { const entry = this.queue.pop() as ProfileCacheQueueEntry; + if (entry) { + // just in case - remove duplicates + this.queue = _.filter(this.queue, (q) => q.name !== entry.name); + } + // console.log('PopFromQueue', entry.name, this.queue.length); return entry; @@ -253,17 +264,42 @@ export class CacheManager { // console.log('Next in queue', next.name, (Date.now() - d) / 1000.0); try { + let skipFetch = false; + + if ( + (next.name in this.ongoingLog) || + ((next.name in this.fetchLog) && (Date.now() - this.fetchLog[next.name] < 120000)) + ) { + skipFetch = true; + } + // tslint:disable-next-line: binary-expression-operand-order if ((false) && (next)) { console.log(`Fetch '${next.name}' for channel '${next.channelId}', gap: ${(Date.now() - this.lastFetch)}ms`); this.lastFetch = Date.now(); } - await this.fetchProfile(next.name); + if (!skipFetch) { + this.ongoingLog[next.name] = true; + + await this.fetchProfile(next.name); + + this.fetchLog[next.name] = Date.now(); + } + + // just in case - remove duplicates + this.queue = _.filter(this.queue, (q) => q.name !== next.name); + delete this.ongoingLog[next.name]; } catch (err) { console.error('Profile queue error', err); - this.queue.push(next); // return to queue + delete this.ongoingLog[next.name]; + + next.retryCount += 1; + + if (next.retryCount < 10) { + this.queue.push(next); // return to queue + } } // console.log('Completed', next.name, (Date.now() - d) / 1000.0); diff --git a/learn/profile-cache.ts b/learn/profile-cache.ts index 9feaa68..7cdee53 100644 --- a/learn/profile-cache.ts +++ b/learn/profile-cache.ts @@ -91,7 +91,7 @@ export class ProfileCache extends AsyncCache { cacheRecord.added = new Date(pd.firstSeen * 1000); cacheRecord.meta = { - lastMetaFetched: pd.lastMetaFetched ? new Date(pd.lastMetaFetched) : null, + lastMetaFetched: pd.lastMetaFetched ? new Date(pd.lastMetaFetched * 1000) : null, groups: pd.groups, friends: pd.friends, images: pd.images, diff --git a/learn/store/worker/client.ts b/learn/store/worker/client.ts index dd92e56..6595392 100644 --- a/learn/store/worker/client.ts +++ b/learn/store/worker/client.ts @@ -59,7 +59,12 @@ export class WorkerClient { } if (res.state === 'ok') { - // log.silly('store.worker.client.msg.ok', { t: (Date.now() - waiter.initiated) / 1000, req: waiter.request }); + const t = Date.now() - waiter.initiated; + + if (t > 200) { + log.info('store.worker.client.msg.slow', { t: t / 1000, req: waiter.request, res }); + } + waiter.resolve(res.result); } else { log.error('store.worker.client.msg.err', { t: (Date.now() - waiter.initiated) / 1000, msg: res.msg, req: waiter.request }); diff --git a/learn/store/worker/store.worker.endpoint.ts b/learn/store/worker/store.worker.endpoint.ts index ed24df5..632b82b 100644 --- a/learn/store/worker/store.worker.endpoint.ts +++ b/learn/store/worker/store.worker.endpoint.ts @@ -8,7 +8,6 @@ type IndexedCallback = (params: Record) => Promise; let indexed: IndexedStore; - const reply = (req: IndexedRequest, result?: any, err?: string | Error): void => { const res: any = { type: 'res', diff --git a/site/character_page/character_page.vue b/site/character_page/character_page.vue index b0ad138..7312f5d 100644 --- a/site/character_page/character_page.vue +++ b/site/character_page/character_page.vue @@ -394,10 +394,12 @@ (cache && !skipCache) && (cache.meta) && (cache.meta.lastMetaFetched) - && (Date.now() - cache.meta.lastMetaFetched.getTime() > CHARACTER_META_CACHE_EXPIRE) + && (Date.now() - cache.meta.lastMetaFetched.getTime() < CHARACTER_META_CACHE_EXPIRE) ) { // do nothing } else { + log.debug('profile.updateMeta', { timestamp: cache?.meta?.lastMetaFetched, diff: Date.now() - (cache?.meta?.lastMetaFetched?.getTime() || 0) }); + // No await on purpose: // tslint:disable-next-line no-floating-promises this.updateMeta(this.name).catch(err => console.error('profile.updateMeta', err));