mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
Merge pull request #2082 from PR0M3TH3AN/perf-explore-data-cache-4578765381783866610
⚡ Optimize collectVideoTags with WeakMap cache
This commit is contained in:
1 file changed
+10
-3
@@ -21,13 +21,19 @@ function normalizeAddressKey(value) {
|
||||
return trimmed.toLowerCase();
|
||||
}
|
||||
|
||||
function collectVideoTags(video) {
|
||||
const tags = new Set();
|
||||
const collectVideoTagsCache = new WeakMap();
|
||||
|
||||
function collectVideoTags(video) {
|
||||
if (!video || typeof video !== "object") {
|
||||
return tags;
|
||||
return new Set();
|
||||
}
|
||||
|
||||
if (collectVideoTagsCache.has(video)) {
|
||||
return collectVideoTagsCache.get(video);
|
||||
}
|
||||
|
||||
const tags = new Set();
|
||||
|
||||
if (Array.isArray(video.tags)) {
|
||||
for (const tag of video.tags) {
|
||||
if (Array.isArray(tag) && tag[0] === "t" && typeof tag[1] === "string") {
|
||||
@@ -51,6 +57,7 @@ function collectVideoTags(video) {
|
||||
}
|
||||
}
|
||||
|
||||
collectVideoTagsCache.set(video, tags);
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user