File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments