Skip to content

Commit eb54c41

Browse files
author
Patryk Lesiewicz
authored
Merge pull request #358 from FirebasePrivate/patryk/next-cleanup
Pull firestore-counter changes from master.
2 parents d10900f + cf80d4b commit eb54c41

File tree

10 files changed

+10
-11378
lines changed

10 files changed

+10
-11378
lines changed

firestore-counter/extension.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ resources:
7373
location: ${LOCATION}
7474
eventTrigger:
7575
eventType: providers/cloud.firestore/eventTypes/document.write
76-
resource: projects/${PROJECT_ID}/databases/(default)/documents/${MOD_METADATA_DOC}/workers/{workerId}
76+
resource: projects/${PROJECT_ID}/databases/(default)/documents/${INTERNAL_STATE_PATH}/workers/{workerId}
7777

7878
params:
7979
- param: LOCATION
@@ -101,7 +101,7 @@ params:
101101
default: us-central1
102102
required: true
103103

104-
- param: MOD_METADATA_DOC
104+
- param: INTERNAL_STATE_PATH
105105
label: Document path for internal state
106106
description: >-
107107
What is the path to the document where the extension can keep its internal state?

firestore-counter/functions/lib/controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class ShardedCounterController {
8989
}
9090
}));
9191
const shutdown = () => __awaiter(this, void 0, void 0, function* () {
92-
console.log("Time's up, shutting down.");
9392
console.log("Successfully ran " +
9493
rounds +
9594
" rounds. Aggregated " +

firestore-counter/functions/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const WORKERS_COLLECTION_ID = "_counter_workers_";
3939
* workers to do the aggregation.
4040
*/
4141
exports.controller = functions.https.onRequest((req, res) => __awaiter(void 0, void 0, void 0, function* () {
42-
const metadocRef = firestore.doc(process.env.MOD_METADATA_DOC);
42+
const metadocRef = firestore.doc(process.env.INTERNAL_STATE_PATH);
4343
const controller = new controller_1.ShardedCounterController(metadocRef, SHARDS_COLLECTION_ID);
4444
let status = yield controller.aggregateOnce({ start: "", end: "" }, 200);
4545
if (status === controller_1.ControllerStatus.WORKERS_RUNNING ||
@@ -58,7 +58,7 @@ exports.controller = functions.https.onRequest((req, res) => __awaiter(void 0, v
5858
* resharding and to detect failed workers that need poking.
5959
*/
6060
exports.worker = functions.firestore
61-
.document(process.env.MOD_METADATA_DOC + WORKERS_COLLECTION_ID + "/{workerId}")
61+
.document(process.env.INTERNAL_STATE_PATH + WORKERS_COLLECTION_ID + "/{workerId}")
6262
.onWrite((change, context) => __awaiter(void 0, void 0, void 0, function* () {
6363
// stop worker if document got deleted
6464
if (!change.after.exists)
@@ -74,7 +74,7 @@ exports.worker = functions.firestore
7474
exports.onWrite = functions.firestore
7575
.document("/{collection}/{**}/_counter_shards_/{shardId}")
7676
.onWrite((change, context) => __awaiter(void 0, void 0, void 0, function* () {
77-
const metadocRef = firestore.doc(process.env.MOD_METADATA_DOC);
77+
const metadocRef = firestore.doc(process.env.INTERNAL_STATE_PATH);
7878
const controller = new controller_1.ShardedCounterController(metadocRef, SHARDS_COLLECTION_ID);
7979
yield controller.aggregateContinuously({ start: "", end: "" }, 200, 60000);
8080
}));

firestore-counter/functions/lib/worker.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ class ShardedCounterWorker {
118118
.then(resolve)
119119
.catch(reject), WORKER_TIMEOUT_MS);
120120
unsubscribeMetadataListener = this.metadoc.ref.onSnapshot((snap) => {
121-
console.log("metadoc update");
122121
// if something's changed in the worker metadata since we were called, abort.
123122
if (!snap.exists || !deepEqual(snap.data(), this.metadata)) {
124-
console.log("shutting down cause metadoc changed.");
123+
console.log("Shutting down because metadoc changed.");
125124
shutdown()
126125
.then(resolve)
127126
.catch(reject);
@@ -283,11 +282,9 @@ function isEmptyPartial(data) {
283282
return false;
284283
if (Object.keys(data).length === 0)
285284
return true;
286-
//console.log("Checking is empty partial: " + JSON.stringify(data));
287285
const update = new aggregator_1.NumericUpdate();
288286
data["_updates_"].forEach((u) => {
289287
update.mergeFrom(u["_data_"]);
290288
});
291-
//console.log("Result: " + update.isNoop());
292289
return update.isNoop();
293290
}

firestore-counter/functions/src/controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export class ShardedCounterController {
109109
});
110110

111111
const shutdown = async () => {
112-
console.log("Time's up, shutting down.");
113112
console.log(
114113
"Successfully ran " +
115114
rounds +

firestore-counter/functions/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const WORKERS_COLLECTION_ID = "_counter_workers_";
3232
* workers to do the aggregation.
3333
*/
3434
export const controller = functions.https.onRequest(async (req, res) => {
35-
const metadocRef = firestore.doc(process.env.MOD_METADATA_DOC);
35+
const metadocRef = firestore.doc(process.env.INTERNAL_STATE_PATH);
3636
const controller = new ShardedCounterController(
3737
metadocRef,
3838
SHARDS_COLLECTION_ID
@@ -58,7 +58,7 @@ export const controller = functions.https.onRequest(async (req, res) => {
5858
*/
5959
export const worker = functions.firestore
6060
.document(
61-
process.env.MOD_METADATA_DOC + WORKERS_COLLECTION_ID + "/{workerId}"
61+
process.env.INTERNAL_STATE_PATH + WORKERS_COLLECTION_ID + "/{workerId}"
6262
)
6363
.onWrite(async (change, context) => {
6464
// stop worker if document got deleted
@@ -76,7 +76,7 @@ export const worker = functions.firestore
7676
export const onWrite = functions.firestore
7777
.document("/{collection}/{**}/_counter_shards_/{shardId}")
7878
.onWrite(async (change, context) => {
79-
const metadocRef = firestore.doc(process.env.MOD_METADATA_DOC);
79+
const metadocRef = firestore.doc(process.env.INTERNAL_STATE_PATH);
8080
const controller = new ShardedCounterController(
8181
metadocRef,
8282
SHARDS_COLLECTION_ID

firestore-counter/functions/src/worker.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ export class ShardedCounterWorker {
138138
);
139139

140140
unsubscribeMetadataListener = this.metadoc.ref.onSnapshot((snap) => {
141-
console.log("metadoc update");
142141
// if something's changed in the worker metadata since we were called, abort.
143142
if (!snap.exists || !deepEqual(snap.data(), this.metadata)) {
144-
console.log("shutting down cause metadoc changed.");
143+
console.log("Shutting down because metadoc changed.");
145144
shutdown()
146145
.then(resolve)
147146
.catch(reject);
@@ -342,11 +341,9 @@ function isEmptyPartial(data: { [key: string]: any }): boolean {
342341
if (Object.keys(data).length === 1 && !("_updates_" in data)) return false;
343342
if (Object.keys(data).length === 0) return true;
344343

345-
//console.log("Checking is empty partial: " + JSON.stringify(data));
346344
const update = new NumericUpdate();
347345
data["_updates_"].forEach((u) => {
348346
update.mergeFrom(u["_data_"]);
349347
});
350-
//console.log("Result: " + update.isNoop());
351348
return update.isNoop();
352349
}

0 commit comments

Comments
 (0)