@gscdump/engine-sqlite 0.37.2 → 0.37.4
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/dist/index.mjs +31 -10
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -16,15 +16,22 @@ function cacheKey(filter) {
|
|
|
16
16
|
function createCachedManifestStore(inner, options = {}) {
|
|
17
17
|
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
18
18
|
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
20
|
+
let generation = 0;
|
|
21
|
+
function invalidateKey(key) {
|
|
22
|
+
cache.delete(key);
|
|
23
|
+
inflight.delete(key);
|
|
24
|
+
}
|
|
19
25
|
function bust(scope) {
|
|
26
|
+
generation++;
|
|
20
27
|
const userId = String(scope.userId);
|
|
21
28
|
if (scope.siteId && scope.table && scope.searchType !== void 0) {
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
invalidateKey(`${userId}\0${scope.siteId}\0${scope.table}\0${scope.searchType}`);
|
|
30
|
+
invalidateKey(`${userId}\0${scope.siteId}\0${scope.table}\0`);
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
const prefix = scope.siteId && scope.table ? `${userId}\0${scope.siteId}\0${scope.table}\0` : scope.siteId ? `${userId}\0${scope.siteId}\0` : `${userId}\0`;
|
|
27
|
-
for (const
|
|
34
|
+
for (const key of /* @__PURE__ */ new Set([...cache.keys(), ...inflight.keys()])) if (key.startsWith(prefix)) invalidateKey(key);
|
|
28
35
|
}
|
|
29
36
|
return {
|
|
30
37
|
listLive: async (filter) => {
|
|
@@ -33,12 +40,20 @@ function createCachedManifestStore(inner, options = {}) {
|
|
|
33
40
|
const now = Date.now();
|
|
34
41
|
const hit = cache.get(k);
|
|
35
42
|
if (hit && hit.expiresAt > now) return hit.value;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
const pending = inflight.get(k);
|
|
44
|
+
if (pending) return pending;
|
|
45
|
+
const loadGeneration = generation;
|
|
46
|
+
const load = inner.listLive(filter).then((value) => {
|
|
47
|
+
if (generation === loadGeneration && inflight.get(k) === load) cache.set(k, {
|
|
48
|
+
value,
|
|
49
|
+
expiresAt: Date.now() + ttlMs
|
|
50
|
+
});
|
|
51
|
+
return value;
|
|
52
|
+
}).finally(() => {
|
|
53
|
+
if (inflight.get(k) === load) inflight.delete(k);
|
|
40
54
|
});
|
|
41
|
-
|
|
55
|
+
inflight.set(k, load);
|
|
56
|
+
return load;
|
|
42
57
|
},
|
|
43
58
|
listAll: inner.listAll.bind(inner),
|
|
44
59
|
registerVersion: async (entry, superseding) => {
|
|
@@ -95,7 +110,11 @@ function createCachedManifestStore(inner, options = {}) {
|
|
|
95
110
|
return result;
|
|
96
111
|
},
|
|
97
112
|
bust,
|
|
98
|
-
clear: () =>
|
|
113
|
+
clear: () => {
|
|
114
|
+
generation++;
|
|
115
|
+
cache.clear();
|
|
116
|
+
inflight.clear();
|
|
117
|
+
},
|
|
99
118
|
stats: () => ({ size: cache.size })
|
|
100
119
|
};
|
|
101
120
|
}
|
|
@@ -608,7 +627,9 @@ function createD1ManifestStore(db) {
|
|
|
608
627
|
await new Promise((resolve) => setTimeout(resolve, jitterDelay()));
|
|
609
628
|
}
|
|
610
629
|
return await fn().finally(async () => {
|
|
611
|
-
await Promise.resolve(db.delete(r2Locks).where(and$1(eq$1(r2Locks.scope, key), eq$1(r2Locks.holderId, holderId))).run()).catch(() => {
|
|
630
|
+
await Promise.resolve(db.delete(r2Locks).where(and$1(eq$1(r2Locks.scope, key), eq$1(r2Locks.holderId, holderId))).run()).catch((error) => {
|
|
631
|
+
console.warn(`[gscdump/engine-sqlite] failed to release manifest lock ${key}; lease will expire`, error);
|
|
632
|
+
});
|
|
612
633
|
});
|
|
613
634
|
}
|
|
614
635
|
async function purgeTenant(filter) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine-sqlite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.37.
|
|
4
|
+
"version": "0.37.4",
|
|
5
5
|
"description": "SQLite / D1 engine adapter for @gscdump/analysis — typed analytics over sqlite-proxy executors (Cloudflare D1, libsql).",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"drizzle-orm": "1.0.0-rc.3"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"
|
|
48
|
-
"gscdump": "0.37.
|
|
47
|
+
"gscdump": "0.37.4",
|
|
48
|
+
"@gscdump/engine": "0.37.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"drizzle-orm": "1.0.0-rc.3",
|