Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions infra/bigquery-export/src/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,19 @@ export class FirestoreBatch {
lastDocId = snapshot.docs[snapshot.docs.length - 1].id

// Shuffle document references in memory to prevent sequential index updates (hotspotting)
const docs = [...snapshot.docs]
for (let i = docs.length - 1; i > 0; i--) {
const len = snapshot.docs.length
const indices = new Uint32Array(len)
for (let i = 0; i < len; i++) indices[i] = i

for (let i = len - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
const temp = docs[i]
docs[i] = docs[j]
docs[j] = temp
const temp = indices[i]
indices[i] = indices[j]
indices[j] = temp
}

for (const doc of docs) {
for (let i = 0; i < len; i++) {
const doc = snapshot.docs[indices[i]]
this.bulkWriter.delete(doc.ref)
this.pendingCount++
partitionDeletedCount++
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"@masthead-data/dataform-package": "0.2.0"
},
"devDependencies": {
"@dataform/cli": "3.0.59",
"eslint": "10.5.0",
"globals": "17.6.0",
"markdownlint-cli": "0.49.0",
"@dataform/cli": "3.0.59"
"markdownlint-cli": "0.49.0"
},
"markdownlint": {
"default": true,
Expand Down