diff options
| author | Martin Ridgers <[email protected]> | 2024-11-11 10:31:34 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-11-11 10:31:34 +0100 |
| commit | 05d1044045539557dfe4e9c8996737d83f9dee89 (patch) | |
| tree | 00907e9a5306318e8a9d169348348b7a5cc1f32d /src/zenserver/frontend/html/indexer/worker.js | |
| parent | Update VERSION.txt (diff) | |
| download | zen-05d1044045539557dfe4e9c8996737d83f9dee89.tar.xz zen-05d1044045539557dfe4e9c8996737d83f9dee89.zip | |
Self-hosted dashboard: Searchable oplog and links between oplog entry dependencies (#213)v5.5.12-pre0
* Consistent use of semicolons
* Added fallback if oplog entry assumptions do not hold
* 'marker' and 'expired' cells were incorrectly friendly
* Two spaces when there should only be one
* Robustness against .text(undefined) calls
* A single step into JavaScript modules
* Turned Fetcher into a module
* Friendly into a module
* Specialise Cbo field name comparison as TextDecoder() is very slow
* Prefer is_named() over get_name()
* Incorrect logic checking if a server reply was okay
* Try and make sure it's always numbers that flow through Friendly
* Added a progress bar component
* Swap key and package hash columns
* CbObject cloning
* Dark and light themes depending on browser settings
* Adjust styling of input boxes
* Add theme swatches to test page
* Turns out one can nest CSS selectors
* Separate swatch for links/actions
* Generate theme by lerping intermediate colours
* Clearer progress bar
* Chromium was complaining about label-less input elements
* Promise-based cache using an IndexedDb
* WebWorker for generating map of package ids to names
* Indexer class for building, loading, and saving map of ids to names
* Added links to oplog entries of an entry's dependencies
* This doesn't need to be decorated as async any longer
* Implemented oplog searching
* View and drop make no sense on package data payloads
* Rudimentary search result truncation
* Updated changelog
* Updated HTML zip archive
Diffstat (limited to 'src/zenserver/frontend/html/indexer/worker.js')
| -rw-r--r-- | src/zenserver/frontend/html/indexer/worker.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/zenserver/frontend/html/indexer/worker.js b/src/zenserver/frontend/html/indexer/worker.js new file mode 100644 index 000000000..581746d6c --- /dev/null +++ b/src/zenserver/frontend/html/indexer/worker.js @@ -0,0 +1,131 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +"use strict"; + +import { Fetcher } from "../util/fetcher.js" + +//////////////////////////////////////////////////////////////////////////////// +export class Message +{ + static None = 0; // + static Init = 1; // project_id, oplog + static Map = 2; // start, end, page_size, stride + static MapPage = 3; // page + static MapDone = 4; // + + static create(msg, ...args) { return [msg, ...args]; } +} + + + +//////////////////////////////////////////////////////////////////////////////// +async function map_id_to_key(project_id, oplog, start, end, page_size, stride) +{ + const uri = "/prj/" + project_id + "/oplog/" + oplog + "/entries"; + while (start < end) + { + performance.mark("fetch"); + const cbo = new Fetcher() + .resource(uri) + .param("start", start) + .param("count", page_size) + .param("fieldfilter", "packagedata,key") + .cbo() + + const entry_count = Math.min(page_size, -(start - end)); + var result = new Array(entry_count); + + var entries = (await cbo).as_object().find("entries"); + if (entries == undefined) + break; + + entries = entries.as_array(); + if (entries.num() == 0) + break; + + performance.mark("build"); + var count = 0; + for (var entry of entries) + { + if (!entry.is_object()) + continue + entry = entry.as_object(); + + var key = undefined; + var pkg_data = undefined; + for (const field of entry) + { + if (field.is_named("key")) key = field; + else if (field.is_named("packagedata")) pkg_data = field; + } + if (key == undefined || pkg_data == undefined) + continue; + + var id = 0n; + for (var item of pkg_data.as_array()) + { + var pkg_id = item.as_object().find("id"); + if (pkg_id == undefined) + continue; + + pkg_id = pkg_id.as_value().subarray(0, 8); + for (var i = 7; i >= 0; --i) + { + id <<= 8n; + id |= BigInt(pkg_id[i]); + } + break; + } + + if (id == 0) + continue; + + result[count] = [id, key.as_value()]; + count++; + } + + start += stride; + + if (count == 0) + continue; + + if (count != result.length) + result = result.slice(0, count); + + performance.mark("sort"); + result.sort(function(l, r) { return Number(l[0] - r[0]); }); + + const msg = Message.create(Message.MapPage, result); + postMessage(msg); + } + + postMessage(Message.create(Message.MapDone)); +} + +//////////////////////////////////////////////////////////////////////////////// +function worker_scope() +{ + var project_id; + var oplog; + + return (evt) => { + const [msg_id, ...params] = evt.data; + switch (msg_id) + { + case Message.Init: + [project_id, oplog] = params; + break; + + case Message.Map: + var [start, end, page_size, stride] = params; + map_id_to_key(project_id, oplog, start, end, page_size, stride); + break; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// +if (typeof DedicatedWorkerGlobalScope != "undefined" && self instanceof DedicatedWorkerGlobalScope) +{ + onmessage = worker_scope(); +} |