@sentio/runtime 2.39.7-rc.18 → 2.39.7-rc.19
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/lib/db-context.d.ts +4 -1
- package/lib/db-context.d.ts.map +1 -1
- package/lib/db-context.js +37 -0
- package/lib/db-context.js.map +1 -1
- package/package.json +2 -2
- package/src/db-context.ts +49 -1
package/lib/db-context.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Subject } from 'rxjs';
|
2
|
-
import { DBRequest, DBResponse, DeepPartial, ProcessStreamResponse } from '@sentio/protos';
|
2
|
+
import { DBRequest, DBRequest_DBUpsert, DBResponse, DeepPartial, ProcessStreamResponse } from '@sentio/protos';
|
3
3
|
type Request = Omit<DBRequest, 'opId'>;
|
4
4
|
export declare const timeoutError: unique symbol;
|
5
5
|
export declare class StoreContext {
|
@@ -13,6 +13,9 @@ export declare class StoreContext {
|
|
13
13
|
result(dbResult: DBResponse): void;
|
14
14
|
error(processId: number, e: any): void;
|
15
15
|
close(): void;
|
16
|
+
queuedUpsert: DBRequest_DBUpsert | undefined;
|
17
|
+
queuedUpsertPromise: Promise<DBResponse> | undefined;
|
18
|
+
private sendUpsert;
|
16
19
|
}
|
17
20
|
export {};
|
18
21
|
//# sourceMappingURL=db-context.d.ts.map
|
package/lib/db-context.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"db-context.d.ts","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,
|
1
|
+
{"version":3,"file":"db-context.d.ts","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,UAAU,EACV,WAAW,EAEX,qBAAqB,EACtB,MAAM,gBAAgB,CAAA;AAEvB,KAAK,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AACtC,eAAO,MAAM,YAAY,eAAW,CAAA;AAEpC,qBAAa,YAAY;IAMrB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM;IAN5B,OAAO,CAAC,MAAM,CAAC,SAAS,CAAK;IAE7B,OAAO,CAAC,MAAM,CAAuF;gBAG1F,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,EACpD,SAAS,EAAE,MAAM;IAG5B,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM;IAM1B,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA6CrF,MAAM,CAAC,QAAQ,EAAE,UAAU;IAc3B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG;IAa/B,KAAK;IAQL,YAAY,EAAE,kBAAkB,GAAG,SAAS,CAAA;IAC5C,mBAAmB,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;YAEtC,UAAU;CA4BzB"}
|
package/lib/db-context.js
CHANGED
@@ -15,6 +15,10 @@ export class StoreContext {
|
|
15
15
|
});
|
16
16
|
}
|
17
17
|
sendRequest(request, timeoutSecs) {
|
18
|
+
if (request.upsert) {
|
19
|
+
// batch upsert if possible
|
20
|
+
return this.sendUpsert(request.upsert);
|
21
|
+
}
|
18
22
|
const opId = StoreContext.opCounter++;
|
19
23
|
const promise = this.newPromise(opId);
|
20
24
|
const start = Date.now();
|
@@ -83,5 +87,38 @@ export class StoreContext {
|
|
83
87
|
}
|
84
88
|
this.defers.clear();
|
85
89
|
}
|
90
|
+
queuedUpsert;
|
91
|
+
queuedUpsertPromise;
|
92
|
+
async sendUpsert(req, batchIdleMs = 1) {
|
93
|
+
if (this.queuedUpsert && this.queuedUpsertPromise) {
|
94
|
+
// merge the upserts
|
95
|
+
req.entity = this.queuedUpsert.entity.concat(req.entity);
|
96
|
+
req.entityData = this.queuedUpsert.entityData.concat(req.entityData);
|
97
|
+
req.id = this.queuedUpsert.id.concat(req.id);
|
98
|
+
req.data = this.queuedUpsert.data.concat(req.data);
|
99
|
+
return this.queuedUpsertPromise;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
this.queuedUpsert = req;
|
103
|
+
const opId = StoreContext.opCounter++;
|
104
|
+
const promise = this.newPromise(opId);
|
105
|
+
this.queuedUpsertPromise = promise;
|
106
|
+
await delay(batchIdleMs);
|
107
|
+
this.queuedUpsertPromise = undefined;
|
108
|
+
this.queuedUpsert = undefined;
|
109
|
+
console.log('sending upsert', opId, 'batch size', req.entity.length);
|
110
|
+
this.subject.next({
|
111
|
+
dbRequest: {
|
112
|
+
upsert: req,
|
113
|
+
opId
|
114
|
+
},
|
115
|
+
processId: this.processId
|
116
|
+
});
|
117
|
+
return promise;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
function delay(ms) {
|
122
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
86
123
|
}
|
87
124
|
//# sourceMappingURL=db-context.js.map
|
package/lib/db-context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"db-context.js","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AACA,OAAO,
|
1
|
+
{"version":3,"file":"db-context.js","sourceRoot":"","sources":["../src/db-context.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,aAAa,EAEd,MAAM,gBAAgB,CAAA;AAGvB,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,EAAE,CAAA;AAEpC,MAAM,OAAO,YAAY;IAMZ;IACA;IANH,MAAM,CAAC,SAAS,GAAG,EAAE,CAAA;IAErB,MAAM,GAAG,IAAI,GAAG,EAA6E,CAAA;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s": "^7.8.1",
|
36
36
|
"utility-types": "^3.11.0",
|
37
37
|
"winston": "^3.11.0",
|
38
|
-
"@sentio/protos": "2.39.7-rc.
|
38
|
+
"@sentio/protos": "2.39.7-rc.19"
|
39
39
|
},
|
40
40
|
"devDependencies": {
|
41
41
|
"@types/command-line-args": "^5.2.3",
|
package/src/db-context.ts
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
import { Subject } from 'rxjs'
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
DBRequest,
|
4
|
+
DBRequest_DBUpsert,
|
5
|
+
DBResponse,
|
6
|
+
DeepPartial,
|
7
|
+
ProcessResult,
|
8
|
+
ProcessStreamResponse
|
9
|
+
} from '@sentio/protos'
|
3
10
|
|
4
11
|
type Request = Omit<DBRequest, 'opId'>
|
5
12
|
export const timeoutError = Symbol()
|
@@ -21,6 +28,11 @@ export class StoreContext {
|
|
21
28
|
}
|
22
29
|
|
23
30
|
sendRequest(request: DeepPartial<Request>, timeoutSecs?: number): Promise<DBResponse> {
|
31
|
+
if (request.upsert) {
|
32
|
+
// batch upsert if possible
|
33
|
+
return this.sendUpsert(request.upsert as DBRequest_DBUpsert)
|
34
|
+
}
|
35
|
+
|
24
36
|
const opId = StoreContext.opCounter++
|
25
37
|
const promise = this.newPromise(opId)
|
26
38
|
|
@@ -94,4 +106,40 @@ export class StoreContext {
|
|
94
106
|
}
|
95
107
|
this.defers.clear()
|
96
108
|
}
|
109
|
+
|
110
|
+
queuedUpsert: DBRequest_DBUpsert | undefined
|
111
|
+
queuedUpsertPromise: Promise<DBResponse> | undefined
|
112
|
+
|
113
|
+
private async sendUpsert(req: DBRequest_DBUpsert, batchIdleMs = 1): Promise<DBResponse> {
|
114
|
+
if (this.queuedUpsert && this.queuedUpsertPromise) {
|
115
|
+
// merge the upserts
|
116
|
+
req.entity = this.queuedUpsert.entity.concat(req.entity)
|
117
|
+
req.entityData = this.queuedUpsert.entityData.concat(req.entityData)
|
118
|
+
req.id = this.queuedUpsert.id.concat(req.id)
|
119
|
+
req.data = this.queuedUpsert.data.concat(req.data)
|
120
|
+
return this.queuedUpsertPromise
|
121
|
+
} else {
|
122
|
+
this.queuedUpsert = req
|
123
|
+
const opId = StoreContext.opCounter++
|
124
|
+
const promise = this.newPromise<DBResponse>(opId)
|
125
|
+
this.queuedUpsertPromise = promise
|
126
|
+
await delay(batchIdleMs)
|
127
|
+
this.queuedUpsertPromise = undefined
|
128
|
+
this.queuedUpsert = undefined
|
129
|
+
console.log('sending upsert', opId, 'batch size', req.entity.length)
|
130
|
+
this.subject.next({
|
131
|
+
dbRequest: {
|
132
|
+
upsert: req,
|
133
|
+
opId
|
134
|
+
},
|
135
|
+
processId: this.processId
|
136
|
+
})
|
137
|
+
|
138
|
+
return promise
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
function delay(ms: number) {
|
144
|
+
return new Promise((resolve) => setTimeout(resolve, ms))
|
97
145
|
}
|