Skip to content

Commit 227a907

Browse files
committed
lazy uuid to work with d1
1 parent c89d99e commit 227a907

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"@cloudflare/workers-types": "^4.20241106.0",
108108
"@miniflare/d1": "^2.14.4",
109109
"@rollup/plugin-commonjs": "^21.0.1",
110+
"@rollup/plugin-json": "^6.1.0",
110111
"@rollup/plugin-node-resolve": "^13.0.0",
111112
"@typescript-eslint/eslint-plugin": "^6.x",
112113
"@typescript-eslint/parser": "^6.x",

src/client/rollup.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import json from '@rollup/plugin-json';
12
import commonjs from '@rollup/plugin-commonjs';
23
import nodeResolve from '@rollup/plugin-node-resolve';
34

45
export default {
5-
input: './src/client/index.js',
6+
input: './src/index.js',
67
output: {
78
file: './src/client/index.mjs',
89
format: 'esm'
910
},
10-
plugins: [commonjs(), nodeResolve({browser: true})],
11+
plugins: [json(), commonjs(), nodeResolve({browser: true})],
1112
external: ['vue']
1213
};

src/table/relation/newManyCache.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var setSessionSingleton = require('../setSessionSingleton');
99

1010
function newManyCache(joinRelation) {
1111
var c = {};
12-
var key = newId();
12+
var key;
1313

1414
c.tryAdd = function(context, parent, child) {
1515
c.getInnerCache(context).tryAdd(parent, child);
@@ -25,10 +25,11 @@ function newManyCache(joinRelation) {
2525
};
2626

2727
c.getInnerCache = function(context) {
28-
var cache = getSessionSingleton(context, key);
28+
const theKey = negotiateKey();
29+
var cache = getSessionSingleton(context, theKey);
2930
if (!cache) {
3031
cache = newCacheCore(joinRelation);
31-
setSessionSingleton(context, key, cache);
32+
setSessionSingleton(context, theKey, cache);
3233
fillCache(context);
3334
synchronizeAdded(context, c.tryAdd.bind(null, context), joinRelation);
3435
synchronizeRemoved(context, c.tryRemove.bind(null, context), joinRelation);
@@ -49,6 +50,13 @@ function newManyCache(joinRelation) {
4950
}
5051
}
5152

53+
function negotiateKey() {
54+
if (key)
55+
return key;
56+
key = newId();
57+
return key;
58+
59+
}
5260

5361

5462
return c;

tests/getMany.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ afterAll(async () => {
3232

3333
beforeAll(async () => {
3434
({ d1, miniflare } = await setupD1(fileURLToPath(import.meta.url)));
35-
console.dir('d1');
36-
console.dir(d1);
37-
console.dir(miniflare);
3835
await createMs('mssql');
3936
await insertData('pg');
4037
await insertData('mssql');

0 commit comments

Comments
 (0)