@naturalcycles/firestore-lib 2.21.0 → 2.23.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { FieldPath } from '@google-cloud/firestore';
|
|
3
|
-
import {
|
|
3
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime';
|
|
4
4
|
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
5
5
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
6
6
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
|
|
@@ -76,7 +76,7 @@ export class FirestoreShardedReadable extends Readable {
|
|
|
76
76
|
return;
|
|
77
77
|
const { logger, table } = this;
|
|
78
78
|
if (this.lastQueryDoneByShard[shard]) {
|
|
79
|
-
this.totalWait +=
|
|
79
|
+
this.totalWait += nowUnixMillis() - this.lastQueryDoneByShard[shard];
|
|
80
80
|
}
|
|
81
81
|
this.queryIsRunningByShard[shard] = true;
|
|
82
82
|
const limit = this.opt.batchSize;
|
|
@@ -107,7 +107,7 @@ export class FirestoreShardedReadable extends Readable {
|
|
|
107
107
|
logger.debug(`${table} got ${rows.length} rows, ${this.rowsRetrieved} rowsRetrieved, totalWait: ${_ms(this.totalWait)}`);
|
|
108
108
|
this.cursorByShard[shard] = lastDocId;
|
|
109
109
|
this.queryIsRunningByShard[shard] = false; // ready to take more _reads
|
|
110
|
-
this.lastQueryDoneByShard[shard] =
|
|
110
|
+
this.lastQueryDoneByShard[shard] = nowUnixMillis();
|
|
111
111
|
for (const row of rows) {
|
|
112
112
|
this.push(row);
|
|
113
113
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { FieldPath } from '@google-cloud/firestore';
|
|
3
|
-
import {
|
|
4
|
-
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
3
|
+
import { _ms, nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
5
4
|
import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js';
|
|
6
5
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log';
|
|
7
6
|
import { pRetry } from '@naturalcycles/js-lib/promise/pRetry.js';
|
|
@@ -89,9 +88,9 @@ export class FirestoreStreamReadable extends Readable {
|
|
|
89
88
|
// rowsRetrieved: this.rowsRetrieved,
|
|
90
89
|
// paused: this.paused,
|
|
91
90
|
// })
|
|
92
|
-
const started =
|
|
91
|
+
const started = nowUnixMillis();
|
|
93
92
|
const qs = await this.runQuery(q);
|
|
94
|
-
const queryTook =
|
|
93
|
+
const queryTook = nowUnixMillis() - started;
|
|
95
94
|
if (!qs) {
|
|
96
95
|
// error already emitted in runQuery
|
|
97
96
|
return;
|
package/dist/query.util.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FieldPath, Timestamp } from '@google-cloud/firestore';
|
|
2
2
|
import { _round } from '@naturalcycles/js-lib';
|
|
3
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js';
|
|
3
4
|
export function readAtToReadTime(opt) {
|
|
4
5
|
if (!opt.readAt)
|
|
5
6
|
return;
|
|
6
7
|
// Same logic as Datastore: round to whole minutes, guard against future
|
|
7
8
|
let readTimeMs = _round(opt.readAt, 60) * 1000;
|
|
8
|
-
if (readTimeMs >=
|
|
9
|
+
if (readTimeMs >= nowUnixMillis() - 1000) {
|
|
9
10
|
readTimeMs -= 60_000;
|
|
10
11
|
}
|
|
11
12
|
return Timestamp.fromMillis(readTimeMs);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"tslib": "^2"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@naturalcycles/dev-lib": "20.
|
|
12
|
+
"@naturalcycles/dev-lib": "20.72.0",
|
|
13
13
|
"@types/node": "^26",
|
|
14
14
|
"typescript": "^7",
|
|
15
15
|
"firebase-admin": "^14"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"engines": {
|
|
39
39
|
"node": ">=26.12.1"
|
|
40
40
|
},
|
|
41
|
-
"version": "2.
|
|
41
|
+
"version": "2.23.0",
|
|
42
42
|
"description": "Firestore implementation of CommonDB interface",
|
|
43
43
|
"author": "Natural Cycles Team",
|
|
44
44
|
"license": "MIT",
|
|
@@ -2,7 +2,7 @@ import { Readable } from 'node:stream'
|
|
|
2
2
|
import { FieldPath } from '@google-cloud/firestore'
|
|
3
3
|
import type { Query, QuerySnapshot } from '@google-cloud/firestore'
|
|
4
4
|
import type { DBQuery } from '@naturalcycles/db-lib'
|
|
5
|
-
import {
|
|
5
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime'
|
|
6
6
|
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
7
7
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
8
8
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
|
|
@@ -107,7 +107,7 @@ export class FirestoreShardedReadable<T extends ObjectWithId = any>
|
|
|
107
107
|
const { logger, table } = this
|
|
108
108
|
|
|
109
109
|
if (this.lastQueryDoneByShard[shard]) {
|
|
110
|
-
this.totalWait +=
|
|
110
|
+
this.totalWait += nowUnixMillis() - this.lastQueryDoneByShard[shard]
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
this.queryIsRunningByShard[shard] = true
|
|
@@ -151,7 +151,7 @@ export class FirestoreShardedReadable<T extends ObjectWithId = any>
|
|
|
151
151
|
|
|
152
152
|
this.cursorByShard[shard] = lastDocId
|
|
153
153
|
this.queryIsRunningByShard[shard] = false // ready to take more _reads
|
|
154
|
-
this.lastQueryDoneByShard[shard] =
|
|
154
|
+
this.lastQueryDoneByShard[shard] = nowUnixMillis()
|
|
155
155
|
|
|
156
156
|
for (const row of rows) {
|
|
157
157
|
this.push(row)
|
|
@@ -7,8 +7,7 @@ import type {
|
|
|
7
7
|
Timestamp,
|
|
8
8
|
} from '@google-cloud/firestore'
|
|
9
9
|
import type { DBQuery } from '@naturalcycles/db-lib'
|
|
10
|
-
import {
|
|
11
|
-
import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
10
|
+
import { _ms, nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
12
11
|
import { TimeoutError } from '@naturalcycles/js-lib/error/error.util.js'
|
|
13
12
|
import { createCommonLoggerAtLevel } from '@naturalcycles/js-lib/log'
|
|
14
13
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
@@ -125,9 +124,9 @@ export class FirestoreStreamReadable<T extends ObjectWithId = any>
|
|
|
125
124
|
// paused: this.paused,
|
|
126
125
|
// })
|
|
127
126
|
|
|
128
|
-
const started =
|
|
127
|
+
const started = nowUnixMillis()
|
|
129
128
|
const qs = await this.runQuery(q)
|
|
130
|
-
const queryTook =
|
|
129
|
+
const queryTook = nowUnixMillis() - started
|
|
131
130
|
if (!qs) {
|
|
132
131
|
// error already emitted in runQuery
|
|
133
132
|
return
|
package/src/query.util.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { FieldPath, Timestamp } from '@google-cloud/firestore'
|
|
|
2
2
|
import type { Query, WhereFilterOp } from '@google-cloud/firestore'
|
|
3
3
|
import type { CommonDBReadOptions, DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
|
|
4
4
|
import { _round } from '@naturalcycles/js-lib'
|
|
5
|
+
import { nowUnixMillis } from '@naturalcycles/js-lib/datetime/time.util.js'
|
|
5
6
|
import type { ObjectWithId } from '@naturalcycles/js-lib/types'
|
|
6
7
|
|
|
7
8
|
export function readAtToReadTime(opt: CommonDBReadOptions): Timestamp | undefined {
|
|
@@ -9,7 +10,7 @@ export function readAtToReadTime(opt: CommonDBReadOptions): Timestamp | undefine
|
|
|
9
10
|
|
|
10
11
|
// Same logic as Datastore: round to whole minutes, guard against future
|
|
11
12
|
let readTimeMs = _round(opt.readAt, 60) * 1000
|
|
12
|
-
if (readTimeMs >=
|
|
13
|
+
if (readTimeMs >= nowUnixMillis() - 1000) {
|
|
13
14
|
readTimeMs -= 60_000
|
|
14
15
|
}
|
|
15
16
|
|