diff --git a/chat/preview/CharacterPreview.vue b/chat/preview/CharacterPreview.vue index 9b18322..da3c844 100644 --- a/chat/preview/CharacterPreview.vue +++ b/chat/preview/CharacterPreview.vue @@ -213,7 +213,7 @@ export default class CharacterPreview extends Vue { updateCustoms(): void { this.customs = _.orderBy( _.map( - _.reject(this.character!.character.customs || [], (c) => _.isUndefined(c)) as CustomKink[], + _.reject(Object.values(this.character!.character.customs ?? []), (c) => _.isUndefined(c)) as CustomKink[], (c: CustomKink) => _.assign( {}, c, diff --git a/learn/matcher.ts b/learn/matcher.ts index bd6f801..0c7753c 100644 --- a/learn/matcher.ts +++ b/learn/matcher.ts @@ -337,9 +337,9 @@ export class Matcher { return _.map( speciesOptions, (species) => { - const nc = _.cloneDeep(c); - - nc.infotags[TagId.Species] = { string: species }; + // Avoid _.cloneDeep because it chokes on array-like objects with very large keys + // _.cloneDeep will happily make arrays with 41 million elements + const nc = {...c, infotags: {...c.infotags, [TagId.Species]: {string: species}}}; return { character: nc, analysis: new CharacterAnalysis(nc) }; } @@ -975,18 +975,14 @@ export class Matcher { private getAllStandardKinks(c: Character): { [key: number]: KinkChoice } { const kinks = _.pickBy(c.kinks, _.isString); - _.each( - c.customs, - (custom: any) => { - if (!custom) { - return; + // Avoid using _.forEach on c.customs because lodash thinks it is an array + for (const custom of Object.values(c.customs)) { + if (custom) { + const children = (custom as any).children ?? {}; + + _.each(children, (child) => kinks[child] = custom.choice); } - - const children = (custom.children) ? custom.children : {}; - - _.each(children, (child) => kinks[child] = custom.choice); - } - ); + } return kinks as any; } diff --git a/learn/store/worker.ts b/learn/store/worker.ts index 37d5af3..5227715 100644 --- a/learn/store/worker.ts +++ b/learn/store/worker.ts @@ -26,7 +26,22 @@ export class WorkerStore implements PermanentIndexedStore { async getProfile(name: string): Promise { - return this.workerClient.request('get', { name }); + const record: ProfileRecord | undefined = await this.workerClient.request('get', { name }); + + // fix custom kinks to prevent hangs + + if (record && Array.isArray(record.profileData.character.customs)) { + // fix customs because it will crash the client + const customsObject: ProfileRecord['profileData']['character']['customs'] = {}; + + for (const [key, value] of Object.entries(record.profileData.character.customs)) { + if (value !== undefined) customsObject[key] = value; + } + + record.profileData.character.customs = customsObject; + } + + return record; }