sliftutils 0.78.0 → 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -12,12 +12,13 @@ export class StorageSync<T> implements IStorageSync<T> {
|
|
|
12
12
|
}, undefined, { deep: false });
|
|
13
13
|
|
|
14
14
|
constructor(public storage: IStorage<T>) {
|
|
15
|
-
storage.watchResync?.(() => {
|
|
16
|
-
this.
|
|
17
|
-
this.infoCached.clear();
|
|
18
|
-
this.keys.clear();
|
|
15
|
+
storage.watchResync?.(async () => {
|
|
16
|
+
// NOTE: If there's multiple tabs open, this'll trigger a lot, so we can't just clear all the values, as that'll cause a render where nothing's loaded.
|
|
19
17
|
this.loadedKeys = false;
|
|
20
|
-
this.
|
|
18
|
+
let keys = await this.getKeysPromise();
|
|
19
|
+
for (let key of keys) {
|
|
20
|
+
this.get(key);
|
|
21
|
+
}
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -55,6 +55,7 @@ const WRITE_DELAY = 500;
|
|
|
55
55
|
interface TransactionEntry {
|
|
56
56
|
key: string;
|
|
57
57
|
value: Buffer | undefined;
|
|
58
|
+
// NOTE: We disabled per-entry zipping. Either use a raw collection so you don't have to load all of them into memory or shard your collection. Zipping is only a band-aid solution for memory issues. ALSO, it makes loading slower, which makes all other applications that don't need zipping worse.
|
|
58
59
|
isZipped: boolean;
|
|
59
60
|
time: number;
|
|
60
61
|
}
|
|
@@ -295,16 +296,17 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
295
296
|
this.diskFiles.set(file, info?.lastModified ?? Date.now());
|
|
296
297
|
}
|
|
297
298
|
|
|
299
|
+
let size = { value: 0 };
|
|
298
300
|
let entryList: TransactionEntry[][] = [];
|
|
299
301
|
for (let file of transactionFiles) {
|
|
300
|
-
entryList.push(await this.parseTransactionFile(file));
|
|
302
|
+
entryList.push(await this.parseTransactionFile(file, size));
|
|
301
303
|
}
|
|
302
304
|
let entries = entryList.flat();
|
|
303
305
|
this.applyTransactionEntries(entries, initialLoad);
|
|
304
306
|
|
|
305
307
|
time = Date.now() - time;
|
|
306
308
|
if (time > 50) {
|
|
307
|
-
console.log(`Loaded ${this.debugName} in ${formatTime(time)}, ${formatNumber(this.cache.size)} keys, from ${formatNumber(transactionFiles.length)} files, entries ${formatNumber(entries.length)}B`, transactionFiles);
|
|
309
|
+
console.log(`Loaded ${this.debugName} in ${formatTime(time)}, ${formatNumber(this.cache.size)} keys, from ${formatNumber(transactionFiles.length)} files, entries ${formatNumber(entries.length)}, total size ${formatNumber(size.value)}B`, transactionFiles);
|
|
308
310
|
}
|
|
309
311
|
|
|
310
312
|
this.init = undefined;
|
|
@@ -312,13 +314,14 @@ export class TransactionStorage implements IStorage<Buffer> {
|
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
// ONLY call this inside of loadAllTransactions
|
|
315
|
-
private async parseTransactionFile(filename: string): Promise<TransactionEntry[]> {
|
|
317
|
+
private async parseTransactionFile(filename: string, size: { value: number }): Promise<TransactionEntry[]> {
|
|
316
318
|
const fullFile = await this.rawStorage.get(filename);
|
|
317
319
|
if (!fullFile) return [];
|
|
318
320
|
if (fullFile.length < 4) {
|
|
319
321
|
//console.error(`Transaction in ${this.debugName} file ${filename} is too small, skipping`);
|
|
320
322
|
return [];
|
|
321
323
|
}
|
|
324
|
+
size.value += fullFile.length;
|
|
322
325
|
let headerSize = fullFile.readUInt32LE(0);
|
|
323
326
|
let headerBuffer = fullFile.slice(4, 4 + headerSize);
|
|
324
327
|
let header: TransactionHeader;
|