From 21a270ca6efa561cad3e87048cf8deb8a166d55f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 8 Sep 2023 08:51:20 -0300 Subject: fix miscellaneous eslint errors --- src/util/wiki-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/util/wiki-data.js') diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index ad2f82fb..0eab2204 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -1,6 +1,6 @@ // Utility functions for interacting with wiki data. -import {accumulateSum, empty, stitchArrays, unique} from './sugar.js'; +import {accumulateSum, empty, unique} from './sugar.js'; // Generic value operations -- cgit 1.3.0-6-gf8a5 From c4f6c41a248ba9ef4f802cc03c20757d417540e4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 9 Sep 2023 21:08:06 -0300 Subject: data: WIP cached composition nonsense --- src/util/wiki-data.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/util/wiki-data.js') diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 0eab2204..ac652b27 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -874,3 +874,71 @@ export function filterItemsForCarousel(items) { .filter(item => item.artTags.every(tag => !tag.isContentWarning)) .slice(0, maxCarouselLayoutItems + 1); } + +// Ridiculous caching support nonsense + +export class TupleMap { + static maxNestedTupleLength = 25; + + #store = [undefined, null, null, null]; + + #lifetime(value) { + if (Array.isArray(value) && value.length <= TupleMap.maxNestedTupleLength) { + return 'tuple'; + } else if ( + typeof value === 'object' && value !== null || + typeof value === 'function' + ) { + return 'weak'; + } else { + return 'strong'; + } + } + + #getSubstoreShallow(value, store) { + const lifetime = this.#lifetime(value); + const mapIndex = {weak: 1, strong: 2, tuple: 3}[lifetime]; + + let map = store[mapIndex]; + if (map === null) { + map = store[mapIndex] = + (lifetime === 'weak' ? new WeakMap() + : lifetime === 'strong' ? new Map() + : lifetime === 'tuple' ? new TupleMap() + : null); + } + + if (map.has(value)) { + return map.get(value); + } else { + const substore = [undefined, null, null, null]; + map.set(value, substore); + return substore; + } + } + + #getSubstoreDeep(tuple, store = this.#store) { + if (tuple.length === 0) { + return store; + } else { + const [first, ...rest] = tuple; + return this.#getSubstoreDeep(rest, this.#getSubstoreShallow(first, store)); + } + } + + get(tuple) { + const store = this.#getSubstoreDeep(tuple); + return store[0]; + } + + has(tuple) { + const store = this.#getSubstoreDeep(tuple); + return store[0] !== undefined; + } + + set(tuple, value) { + const store = this.#getSubstoreDeep(tuple); + store[0] = value; + return value; + } +} -- cgit 1.3.0-6-gf8a5 From e842ce93e6405334b6ef475ec1db41e051cfd2b5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 11 Oct 2023 14:49:43 -0300 Subject: data: use flash act directory for better determinism --- src/util/wiki-data.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/util/wiki-data.js') diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index ac652b27..0790ae91 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -610,20 +610,9 @@ export function sortFlashesChronologically(data, { latestFirst = false, getDate, } = {}) { - // Flash acts don't actually have any identifying properties because they - // don't have dedicated pages (yet), so don't have a directory. Make up a - // fake key identifying them so flashes can be grouped together. - const flashActs = new Set(data.map(flash => flash.act)); - const flashActIdentifiers = new Map(); - - let counter = 0; - for (const act of flashActs) { - flashActIdentifiers.set(act, ++counter); - } - // Group flashes by act... - data.sort((a, b) => { - return flashActIdentifiers.get(a.act) - flashActIdentifiers.get(b.act); + sortByDirectory(data, { + getDirectory: flash => flash.act.directory, }); // Sort flashes by position in act... -- cgit 1.3.0-6-gf8a5