Mercurial > code > home > repos > gcalendarwatch
annotate calsync/mongoclient/events_collection.go @ 56:635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
author | drewp@bigasterisk.com |
---|---|
date | Thu, 05 Sep 2024 13:50:40 -0700 |
parents | a9b720445bcf |
children | 6c7151126a0b |
rev | line source |
---|---|
50 | 1 package mongoclient |
2 | |
3 import ( | |
4 "log" | |
51
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
5 "time" |
50 | 6 |
7 "go.mongodb.org/mongo-driver/bson" | |
8 "go.mongodb.org/mongo-driver/mongo/options" | |
9 ) | |
10 | |
56
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
11 func LogWithCal(cal MongoCal, msg ...interface{}) { |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
12 log.Println("cal:", (cal.GoogleId+"........")[:8], msg) |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
13 } |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
14 |
50 | 15 func (c *MongoClient) UpsertOneEvent(ev MongoEvent) error { |
16 filter := bson.M{"_id": ev.Url} | |
51
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
17 setFields := ev |
50 | 18 update := bson.M{"$set": setFields} |
19 _, err := c.eventsCollection.UpdateOne(c.ctx, filter, update, options.Update().SetUpsert(true)) | |
20 if err != nil { | |
21 return err | |
22 } | |
23 return nil | |
24 } | |
25 | |
56
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
26 func (c *MongoClient) DeleteEventsUpdatedBefore(cal MongoCal, t time.Time) error { |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
27 res, err := c.eventsCollection.DeleteMany( |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
28 c.ctx, |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
29 bson.M{"calendarUrl": cal.Url, |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
30 "lastUpdated": bson.M{"$lt": t}}) |
635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
drewp@bigasterisk.com
parents:
51
diff
changeset
|
31 LogWithCal(cal, "deleted", res.DeletedCount, "events updated before", t) |
51
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
32 if err != nil { |
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
33 return err |
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
34 } |
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
35 return nil |
a9b720445bcf
now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents:
50
diff
changeset
|
36 } |