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/cache.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/cache.js')
| -rw-r--r-- | src/zenserver/frontend/html/indexer/cache.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/zenserver/frontend/html/indexer/cache.js b/src/zenserver/frontend/html/indexer/cache.js new file mode 100644 index 000000000..390aa948d --- /dev/null +++ b/src/zenserver/frontend/html/indexer/cache.js @@ -0,0 +1,65 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +"use strict"; + +//////////////////////////////////////////////////////////////////////////////// +export class Cache +{ + constructor(db_name, ...store_names) + { + this._db_name = db_name; + this._store_names = store_names; + this._version = 1; + this._db = this._open(); + } + + put(store_name, key, value) + { + const executor = async (resolve, reject) => { + const db = await this._db; + const transaction = db.transaction(store_name, "readwrite"); + const store = transaction.objectStore(store_name); + const request = store.put(value, key); + request.onerror = (evt) => reject(Error("put transaction error")); + request.onsuccess = (evt) => resolve(true); + }; + return new Promise(executor); + } + + get(store_name, key) + { + const executor = async (resolve, reject) => { + const db = await this._db; + const transaction = db.transaction(store_name, "readonly"); + const store = transaction.objectStore(store_name); + const request = store.get(key); + request.onerror = (evt) => reject(Error("get transaction error")); + request.onsuccess = (evt) => { + if (request.result) + resolve(request.result); + else + resolve(false); + }; + }; + return new Promise(executor); + } + + _open() + { + const executor = (resolve, reject) => { + const request = indexedDB.open(this._db_name, this._version); + request.onerror = (evt) => reject(Error("Failed to open IndexedDb")); + request.onsuccess = (evt) => resolve(evt.target.result); + request.onupgradeneeded = (evt) => { + const db = evt.target.result; + + for (const store_name of db.objectStoreNames) + db.deleteObjectStore(store_name) + + for (const store_name of this._store_names) + db.createObjectStore(store_name); + }; + }; + return new Promise(executor); + } +} |