Skip to content

Commit fd2d47a

Browse files
committed
fix(notifications): Add script to set notificationFrequency to Weekly for all current users. This pairs with the recent change to set the default notificationFrequency to Weekly.
1 parent eda777c commit fd2d47a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Script } from "./types"
2+
3+
const BATCH_SIZE = 100
4+
5+
export const script: Script = async ({ db }) => {
6+
console.log("Setting notificationFrequency to Weekly for all users")
7+
let numProfilesUpdated = 0
8+
let numProfilesSkipped = 0
9+
10+
let profiles = await db.collection("profiles").limit(BATCH_SIZE).get()
11+
12+
do {
13+
const lastDoc = profiles.docs[profiles.docs.length - 1]
14+
15+
const batch = db.batch()
16+
for (const doc of profiles.docs) {
17+
if (doc.data().notificationFrequency === "None") {
18+
// Preserve "None" settings (since these may be intentional opt-outs)
19+
numProfilesSkipped++
20+
console.log(
21+
`Skipping user ${doc.id} with notification frequency set to None.`
22+
)
23+
} else {
24+
numProfilesUpdated++
25+
batch.update(doc.ref, { notificationFrequency: "Weekly" })
26+
console.log(`Updating user ${doc.id} notification frequency to Weekly.`)
27+
}
28+
}
29+
30+
numProfilesUpdated += profiles.docs.length
31+
await batch.commit()
32+
33+
profiles = await db
34+
.collection("profiles")
35+
.startAfter(lastDoc)
36+
.limit(BATCH_SIZE)
37+
.get()
38+
} while (profiles.docs.length > 0)
39+
40+
console.log(
41+
`Finished updating notification frequency. Updated ${numProfilesUpdated} profiles, skipped ${numProfilesSkipped} profiles.`
42+
)
43+
}

0 commit comments

Comments
 (0)