datafolder 1.0.33 → 1.0.35

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/ChangeLog.md CHANGED
@@ -1,3 +1,7 @@
1
+ 1.0.35 Split logger into main logger and worker logger to log all messages.
2
+
3
+ 1.0.34 Use indexCount to improve query performance.
4
+
1
5
  1.0.33 Buffer messages before file saver started and send to file saver after it started.
2
6
 
3
7
  1.0.32 Query performance improvement.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datafolder",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "author": {
5
5
  "name": "lysh",
6
6
  "email": "datafolderdev@outlook.com"
package/src/QyBatch.js CHANGED
@@ -13,11 +13,11 @@ import {
13
13
  getSuffix as g,
14
14
  SpecialFilePaths as e,
15
15
  isSimpleType as d,
16
- isEmptyObj as l,
16
+ isEmptyObj as u,
17
17
  isNumber as r,
18
- getNowRounded as m,
18
+ getNowRounded as l,
19
19
  isDate as a,
20
- isArray as u,
20
+ isArray as m,
21
21
  isFloat32Array as f
22
22
  } from "./QyUtils.js";
23
23
 
@@ -35,11 +35,11 @@ import {
35
35
  } from "./QyDefaultOptions.js";
36
36
 
37
37
  import {
38
- QyCD as v
38
+ QyCD as C
39
39
  } from "./QyCD.js";
40
40
 
41
41
  import {
42
- logger as C
42
+ logger as v
43
43
  } from "./QyLogger.js";
44
44
 
45
45
  let y = e.IndexPropPathsFileName, x = {
@@ -49,7 +49,7 @@ let y = e.IndexPropPathsFileName, x = {
49
49
  all: 3
50
50
  };
51
51
 
52
- class D extends v {
52
+ class D extends C {
53
53
  fileLogLevel;
54
54
  changeId;
55
55
  actionQueue = [];
@@ -127,7 +127,7 @@ class D extends v {
127
127
  });
128
128
  }
129
129
  createIndex(e, t, i = this.currentDir) {
130
- h(e) && (e = o(e)), u(t) || (t = [ t ]);
130
+ h(e) && (e = o(e)), m(t) || (t = [ t ]);
131
131
  e = this.qyCache.getOrCreateDir(e, i);
132
132
  return F(this, this._action_createIndex, {
133
133
  item: e,
@@ -315,7 +315,7 @@ ${r}
315
315
  if (0 !== i.length) {
316
316
  var a, o = {};
317
317
  for (a of i) o[JSON.stringify(a.indexPropPath)] = 1;
318
- C.log(`Creating index ${JSON.stringify(o)} for ` + t.fullPath), this._action_insert({
318
+ v.log(`Creating index ${JSON.stringify(o)} for ` + t.fullPath), this._action_insert({
319
319
  item: r,
320
320
  content: o
321
321
  });
@@ -455,7 +455,7 @@ ${r}
455
455
  item: t,
456
456
  content: i
457
457
  } = e;
458
- if (void 0 === i) return C.warn(`Saving undefined to ${t.fullPath}. Not making any change.`),
458
+ if (void 0 === i) return v.warn(`Saving undefined to ${t.fullPath}. Not making any change.`),
459
459
  !1;
460
460
  t.created || this._action_createFile({
461
461
  item: t
@@ -487,7 +487,7 @@ ${r}
487
487
  merged: a,
488
488
  delta: o
489
489
  } = e;
490
- if (void 0 === o && void 0 === r) return C.warn(`Saving undefined to ${i.fullPath}. Not making any change.`),
490
+ if (void 0 === o && void 0 === r) return v.warn(`Saving undefined to ${i.fullPath}. Not making any change.`),
491
491
  !1;
492
492
  if (!i.created) {
493
493
  if (n) return !1;
@@ -532,7 +532,7 @@ ${r}
532
532
  parentDir: r,
533
533
  name: n
534
534
  } = e;
535
- return void 0 !== r && void 0 !== (i = I(i, !0, m())) && (t = this.qyCache,
535
+ return void 0 !== r && void 0 !== (i = I(i, !0, l())) && (t = this.qyCache,
536
536
  r = t.getOrCreateExpireInfoFile(r.fullPathHash, e.isFile ? "f" : "d"), (r = this._action_insert({
537
537
  item: r,
538
538
  content: {
@@ -554,7 +554,7 @@ ${r}
554
554
  content: {
555
555
  [n]: null
556
556
  }
557
- })) && (l(r.fileContent) && this._action_delFile({
557
+ })) && (u(r.fileContent) && this._action_delFile({
558
558
  item: r
559
559
  }), void 0 === i) && t.unmonitorItemExpire(e), n);
560
560
  }
@@ -564,7 +564,7 @@ ${r}
564
564
  item: t,
565
565
  expireInfoObj: i,
566
566
  isMilliSecond: r
567
- } = e, n = m();
567
+ } = e, n = l();
568
568
  var e = b(i, e => I(e, r, n)), a = this.qyCache, o = a.getOrCreateExpireInfoFile(t.fullPathHash, "c"), o = this._action_insert({
569
569
  item: o,
570
570
  content: {
@@ -580,11 +580,11 @@ ${r}
580
580
  expireInfoObj: i,
581
581
  infoFileOnly: r
582
582
  } = e, n = this.qyCache, a = n.getExpireInfoFile(e.fullPathHash, "c");
583
- return void 0 !== a && (i = u(i) ? Object.fromEntries(i.map(e => [ e, null ])) : b(i, e => e ? null : void 0),
583
+ return void 0 !== a && (i = m(i) ? Object.fromEntries(i.map(e => [ e, null ])) : b(i, e => e ? null : void 0),
584
584
  (t = this._action_insert({
585
585
  item: a,
586
586
  content: i
587
- })) && (l(a.fileContent, !0) && this._action_delFile({
587
+ })) && (u(a.fileContent, !0) && this._action_delFile({
588
588
  item: a
589
589
  }), r || n.unmonitorContentExpire(e, i)), t);
590
590
  }
@@ -624,7 +624,7 @@ function P(e, t, i, r, n = void 0, a = void 0) {
624
624
  changeId: h
625
625
  } = e;
626
626
  e.pushCmd(i, r, n, a), r.startsWith("d") ? t.dChangeId = h : r.startsWith("f") ? t.fChangeId = h : t.cChangeId = h,
627
- o && o.qyKVData.removeKey(r) && s.push(r, t);
627
+ void 0 !== o && o.qyKVData.removeKey(r) && s.push(r, t);
628
628
  }
629
629
 
630
630
  function q(e, t, i, r = void 0, n = void 0) {
@@ -648,9 +648,11 @@ function N(t, e, i, r, n, a, o = void 0) {
648
648
  if (void 0 !== e) {
649
649
  var s, h, [ i, n ] = e;
650
650
  for (s of i) {
651
- t._action_setProp(s, r, null);
652
- var d = s.fileContent;
653
- if (void 0 === d || l(d)) {
651
+ var {
652
+ fileContent: d,
653
+ indexCount: c
654
+ } = s, l = t._action_setProp(s, r, null);
655
+ if (void 0 === d || u(d)) {
654
656
  t._action_delFile({
655
657
  item: s
656
658
  });
@@ -658,9 +660,12 @@ function N(t, e, i, r, n, a, o = void 0) {
658
660
  for (;e.created && !e.isHiddenFolder && e.isEmpty; ) t._action_delDir({
659
661
  item: e
660
662
  }), e = e.parentDir;
661
- }
663
+ } else void 0 !== l && (s.indexCount = c - 1);
664
+ }
665
+ for (h of n) {
666
+ var m = h.indexCount;
667
+ 1 !== t._action_setProp(h, r, 1) && (h.indexCount = m + 1);
662
668
  }
663
- for (h of n) t._action_setProp(h, r, 1);
664
669
  }
665
670
  }
666
671
 
package/src/QyCache.js CHANGED
@@ -23,9 +23,9 @@ import {
23
23
 
24
24
  import {
25
25
  isString as C,
26
- lockExclusiveFilePath as x,
26
+ lockExclusiveFilePath as q,
27
27
  unlockExclusiveFilePath as o,
28
- ensureDir as q,
28
+ ensureDir as x,
29
29
  SpecialFilePaths as e
30
30
  } from "./QyUtils.js";
31
31
 
@@ -63,10 +63,10 @@ import {
63
63
 
64
64
  let {
65
65
  HiddenFolderName: D,
66
- IndexDirPath: y,
66
+ IndexDirPath: F,
67
67
  TriggerDirPath: w,
68
68
  RpcDirPath: E,
69
- ExpireDirPath: F,
69
+ ExpireDirPath: y,
70
70
  MetaFilePath: t,
71
71
  HNSWDirPath: m,
72
72
  InfoDirPath: f,
@@ -101,7 +101,7 @@ class i extends r {
101
101
  t._subdirMap = {
102
102
  [D]: a
103
103
  }, a._subdirMap = {};
104
- for ([ s, i ] of [ [ y, "indexRootDir" ], [ F, "expireRootDir" ], [ m, "hnswRootDir" ], [ f, "infoRootDir" ], [ Q, "recycleRootDir" ] ]) {
104
+ for ([ s, i ] of [ [ F, "indexRootDir" ], [ y, "expireRootDir" ], [ m, "hnswRootDir" ], [ f, "infoRootDir" ], [ Q, "recycleRootDir" ] ]) {
105
105
  var s = s.at(-1), n = new l(s, !0, a);
106
106
  a._subdirMap[s] = n, o[i] = n;
107
107
  }
@@ -128,13 +128,8 @@ class i extends r {
128
128
  } = this;
129
129
  P.log("Starting at " + r);
130
130
  try {
131
- await q(e);
132
- var [ {
133
- maxChangeId: l,
134
- loadedMaxAclNum: g,
135
- qySnapshots: h,
136
- aclKeyValueMap: d
137
- } ] = await Promise.all([ ((r, e) => (r = new b(r, e)).load())(e, t), x(a) ]);
131
+ await x(e);
132
+ var [ [ l, g, h, d ] ] = await Promise.all([ ((r, e) => (r = new b(r, e)).load())(e, t), q(a) ]);
138
133
  o.start(), i.start(l, g, h, d), await n.start();
139
134
  } catch (r) {
140
135
  throw o.stop(), n.stop(), r;
@@ -152,17 +147,17 @@ class i extends r {
152
147
  var {
153
148
  name: p,
154
149
  fileContent: c
155
- } = p, [ c, D, y ] = c;
156
- u.insertTriggerToTree(p, c, D, y);
150
+ } = p, [ c, D, F ] = c;
151
+ u.insertTriggerToTree(p, c, D, F);
157
152
  }
158
- var F = this;
159
- F.rpcRootDir = F.rootDir.searchOrCreateSubdir(E);
160
- for (m of F.rpcRootDir.fileList) {
153
+ var y = this;
154
+ y.rpcRootDir = y.rootDir.searchOrCreateSubdir(E);
155
+ for (m of y.rpcRootDir.fileList) {
161
156
  var {
162
157
  name: m,
163
158
  fileContent: f
164
159
  } = m;
165
- C(f) && F.insertRpc(m, f);
160
+ C(f) && y.insertRpc(m, f);
166
161
  }
167
162
  return t.dumpStructureAtStart && await O(v(r, "qystruct"), s), P.log("Started."),
168
163
  this;
package/src/QyDir.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare class QyDir extends QyItem {
8
8
  fileMapChangeCount: number;
9
9
  dChangeId: number;
10
10
  fChangeId: number;
11
- cache: {};
11
+ valueCache: {};
12
12
  constructor(name: string | number, created?: boolean, parentDir?: QyDir | undefined, qyCache?: QyCache | undefined);
13
13
  get created(): boolean;
14
14
  set created(val: boolean);
package/src/QyDir.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  getSubdirMapKey as i,
7
7
  getFileMapKey as t,
8
8
  SpecialFilePaths as r,
9
- isString as h,
10
- getNowTime as n
9
+ isString as l,
10
+ getNowTime as o
11
11
  } from "./QyUtils.js";
12
12
 
13
13
  import {
@@ -15,7 +15,7 @@ import {
15
15
  } from "./QyFile.js";
16
16
 
17
17
  import {
18
- handleExpiredItem as o
18
+ handleExpiredItem as h
19
19
  } from "./QyExpire.js";
20
20
 
21
21
  let s = r.HiddenFolderName;
@@ -27,7 +27,7 @@ class d extends e {
27
27
  fileMapChangeCount = 0;
28
28
  dChangeId = 0;
29
29
  fChangeId = 0;
30
- cache = {};
30
+ valueCache = {};
31
31
  constructor(e, i = !1, t = void 0, r = void 0) {
32
32
  super(e, i, t), r && (this._qyCache = r), t && i && (++t._subdirCount, ++t.subdirMapChangeCount);
33
33
  }
@@ -36,14 +36,14 @@ class d extends e {
36
36
  }
37
37
  set created(e) {
38
38
  var i;
39
- this._created !== (e = !!e) && (this._created = e, i = this.parentDir, i) && (i._subdirCount += e ? 1 : -1,
39
+ this._created !== e && (this._created = e, i = this.parentDir, i) && (i._subdirCount += e ? 1 : -1,
40
40
  ++i.subdirMapChangeCount);
41
41
  }
42
42
  get fileCount() {
43
- return f(this), this._fileCount;
43
+ return n(this), this._fileCount;
44
44
  }
45
45
  get subdirCount() {
46
- return l(this), this._subdirCount;
46
+ return u(this), this._subdirCount;
47
47
  }
48
48
  get isDir() {
49
49
  return !0;
@@ -61,10 +61,10 @@ class d extends e {
61
61
  return this._fileMapKey || (this._fileMapKey = t(this.fullPathHash));
62
62
  }
63
63
  get subdirMap() {
64
- return l(this), this._subdirMap;
64
+ return u(this), this._subdirMap;
65
65
  }
66
66
  get fileMap() {
67
- return f(this), this._fileMap;
67
+ return n(this), this._fileMap;
68
68
  }
69
69
  getSubdir(e) {
70
70
  var i;
@@ -117,28 +117,100 @@ class d extends e {
117
117
  return this.searchOrCreateSubdir(e, i, e.length - 1).getOrCreateFile(e.at(-1), i);
118
118
  }
119
119
  get subdirList() {
120
- return u(this, "_subdirList", this.subdirMapChangeCount, () => this.created && this.subdirMap ? Object.values(this.subdirMap).filter(e => e.created) : []);
120
+ var {
121
+ valueCache: e,
122
+ subdirMapChangeCount: i
123
+ } = this;
124
+ let {
125
+ _subdirList: t,
126
+ _subdirListChangeCount: r
127
+ } = e;
128
+ return void 0 !== t && r === i || (t = e._subdirList = this.created && this.subdirMap ? Object.values(this.subdirMap).filter(e => e.created) : [],
129
+ e._subdirListChangeCount = i), t;
121
130
  }
122
131
  get subdirNameList() {
123
- return u(this, "_subdirNameList", this.subdirMapChangeCount, () => this.subdirList.map(e => e.name));
132
+ var {
133
+ valueCache: e,
134
+ subdirMapChangeCount: i
135
+ } = this;
136
+ let {
137
+ _subdirNameList: t,
138
+ _subdirNameListChangeCount: r
139
+ } = e;
140
+ return void 0 !== t && r === i || (t = e._subdirNameList = this.subdirList.map(e => e.name),
141
+ e._subdirNameListChangeCount = i), t;
124
142
  }
125
143
  get sortedSubdirList() {
126
- return u(this, "_sortedSubdirList", this.subdirMapChangeCount, () => this.subdirList.sort((e, i) => e.cmp(i)));
144
+ var {
145
+ valueCache: e,
146
+ subdirMapChangeCount: i
147
+ } = this;
148
+ let {
149
+ _sortedSubdirList: t,
150
+ _sortedSubdirListChangeCount: r
151
+ } = e;
152
+ return void 0 !== t && r === i || (t = e._sortedSubdirList = this.subdirList.sort((e, i) => e.cmp(i)),
153
+ e._sortedSubdirListChangeCount = i), t;
127
154
  }
128
155
  get sortedSubdirNameList() {
129
- return u(this, "_sortedSubdirNameList", this.subdirMapChangeCount, () => this.sortedSubdirList.map(e => e.nameNum));
156
+ var {
157
+ valueCache: e,
158
+ subdirMapChangeCount: i
159
+ } = this;
160
+ let {
161
+ _sortedSubdirNameList: t,
162
+ _sortedSubdirNameListChangeCount: r
163
+ } = e;
164
+ return void 0 !== t && r === i || (t = e._sortedSubdirNameList = this.sortedSubdirList.map(e => e.nameNum),
165
+ e._sortedSubdirNameListChangeCount = i), t;
130
166
  }
131
167
  get fileList() {
132
- return u(this, "_fileList", this.fileMapChangeCount, () => this.created && this.fileMap ? Object.values(this.fileMap).filter(e => e.created) : []);
168
+ var {
169
+ valueCache: e,
170
+ fileMapChangeCount: i
171
+ } = this;
172
+ let {
173
+ _fileList: t,
174
+ _fileListChangeCount: r
175
+ } = e;
176
+ return void 0 !== t && r === i || (t = e._fileList = this.created && this.fileMap ? Object.values(this.fileMap).filter(e => e.created) : [],
177
+ e._fileListChangeCount = i), t;
133
178
  }
134
179
  get fileNameList() {
135
- return u(this, "_fileNameList", this.fileMapChangeCount, () => this.fileList.map(e => e.name));
180
+ var {
181
+ valueCache: e,
182
+ fileMapChangeCount: i
183
+ } = this;
184
+ let {
185
+ _fileNameList: t,
186
+ _fileNameListChangeCount: r
187
+ } = e;
188
+ return void 0 !== t && r === i || (t = e._fileNameList = this.fileList.map(e => e.name),
189
+ e._fileNameListChangeCount = i), t;
136
190
  }
137
191
  get sortedFileList() {
138
- return u(this, "_sortedFileList", this.fileMapChangeCount, () => this.fileList.sort((e, i) => e.cmp(i)));
192
+ var {
193
+ valueCache: e,
194
+ fileMapChangeCount: i
195
+ } = this;
196
+ let {
197
+ _sortedFileList: t,
198
+ _sortedFileListChangeCount: r
199
+ } = e;
200
+ return void 0 !== t && r === i || (t = e._sortedFileList = this.fileList.sort((e, i) => e.cmp(i)),
201
+ e._sortedFileListChangeCount = i), t;
139
202
  }
140
203
  get sortedFileNameList() {
141
- return u(this, "_sortedFileNameList", this.fileMapChangeCount, () => this.sortedFileList.map(e => e.nameNum));
204
+ var {
205
+ valueCache: e,
206
+ fileMapChangeCount: i
207
+ } = this;
208
+ let {
209
+ _sortedFileNameList: t,
210
+ _sortedFileNameListChangeCount: r
211
+ } = e;
212
+ return void 0 !== t && r === i || (t = e._sortedFileNameList = this.sortedFileList.map(e => e.nameNum),
213
+ e._sortedFileNameListChangeCount = i), t;
142
214
  }
143
215
  *allSubdirs() {
144
216
  var e, i, t = this.subdirList;
@@ -181,7 +253,7 @@ class d extends e {
181
253
  var a = r.length;
182
254
  for (let e = t ? a - 1 : 0; t ? 0 <= e : e < a; t ? --e : ++e) {
183
255
  var d = r[e], u = d.nameNum;
184
- if (h(u)) {
256
+ if (l(u)) {
185
257
  if (s) return;
186
258
  } else if (i(u)) yield d, s = !0; else if (s) return;
187
259
  }
@@ -192,12 +264,7 @@ class d extends e {
192
264
  }
193
265
  }
194
266
 
195
- function u(e, i, t, r) {
196
- var e = e.cache, s = i + "ChangeCount";
197
- return void 0 !== e[i] && e[s] === t || (e[i] = r(), e[s] = t), e[i];
198
- }
199
-
200
- function l(e) {
267
+ function u(e) {
201
268
  if (e.created && !e.subdirMapLoaded) {
202
269
  e.subdirMapLoaded = !0;
203
270
  var i = e.qyCache;
@@ -206,13 +273,13 @@ function l(e) {
206
273
  if (t) {
207
274
  var r, s = e._subdirMap || (e._subdirMap = {});
208
275
  for (r in t) r in s || (s[r] = new d(r, !0, e));
209
- e.underHiddenFolder || p(e, i, "d");
276
+ e.underHiddenFolder || f(e, i, "d");
210
277
  }
211
278
  }
212
279
  }
213
280
  }
214
281
 
215
- function f(e) {
282
+ function n(e) {
216
283
  if (e.created && !e._fileMap && !e.fileMapLoaded) {
217
284
  e.fileMapLoaded = !0;
218
285
  var i = e.qyCache;
@@ -221,13 +288,13 @@ function f(e) {
221
288
  if (t) {
222
289
  var r, s = e._fileMap = {};
223
290
  for (r in t) s[r] = new a(r, !0, e);
224
- e.underHiddenFolder || p(e, i, "f");
291
+ e.underHiddenFolder || f(e, i, "f");
225
292
  }
226
293
  }
227
294
  }
228
295
  }
229
296
 
230
- function p(e, i, t) {
297
+ function f(e, i, t) {
231
298
  if ("d" === t) {
232
299
  if (e.dExpireChecked) return;
233
300
  e.dExpireChecked = !0;
@@ -237,10 +304,10 @@ function p(e, i, t) {
237
304
  }
238
305
  var r = i.getExpireInfoFile(e.fullPathHash, t);
239
306
  if (void 0 !== r) {
240
- var s, a = r.fileContent, d = n(), u = i.qyDB;
307
+ var s, a = r.fileContent, d = o(), u = i.qyDB;
241
308
  for (s in a) {
242
- var h = "d" === t ? e.getOrCreateSubdir(s) : e.getOrCreateFile(s), l = a[s];
243
- l <= d ? o(u, h) : i.monitorItemExpire(h, l);
309
+ var l = "d" === t ? e.getOrCreateSubdir(s) : e.getOrCreateFile(s), n = a[s];
310
+ n <= d ? h(u, l) : i.monitorItemExpire(l, n);
244
311
  }
245
312
  }
246
313
  }
package/src/QyFile.d.ts CHANGED
@@ -14,8 +14,10 @@ export declare class QyFile extends QyItem {
14
14
  get isFile(): boolean;
15
15
  get contentAsText(): any;
16
16
  get clonedContent(): any;
17
+ get indexCount(): any;
18
+ set indexCount(val: any);
17
19
  view(spec: string | undefined, noClone: any): any;
18
20
  prop(namePath: any, spec: string | undefined, noClone: any): any;
19
21
  unloadFileContent(): void;
20
- ensureLoaded(): this | undefined;
22
+ ensureLoaded(): this;
21
23
  }