Skip to content

Commit bd2def4

Browse files
authored
fewer writes (#30)
1 parent 8aa1cff commit bd2def4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

server/forum_indexer.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ func (indexer *ForumIndexer) index(locale *Locale, poster string, timezone *time
198198
"poster": poster,
199199
})
200200

201-
cutoff := time.Now().Add(time.Hour * -12)
201+
pageCutoff := time.Now().Add(-12 * time.Hour)
202+
cutoff := time.Now().Add(-14 * 24 * time.Hour)
202203
activity := []Activity(nil)
203204

204205
for page := 1; ; page++ {
@@ -209,13 +210,16 @@ func (indexer *ForumIndexer) index(locale *Locale, poster string, timezone *time
209210

210211
done := len(posts) == 0
211212
for _, post := range posts {
212-
if post.Time.Before(cutoff) {
213+
if post.Time.Before(pageCutoff) {
213214
done = true
214215
}
216+
if post.Time.Before(cutoff) {
217+
break
218+
}
215219
activity = append(activity, post)
216220
}
217221

218-
logger.WithField("count", len(posts)).Info("received forum posts")
222+
logger.WithField("count", len(activity)).Info("received forum posts")
219223

220224
if done {
221225
break

server/reddit_indexer.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (indexer *RedditIndexer) run() {
5757
if next >= len(users) {
5858
next = 0
5959
}
60-
time.Sleep(time.Second * 2)
60+
time.Sleep(time.Second * 3)
6161
}
6262
}
6363
}
@@ -151,7 +151,8 @@ func (indexer *RedditIndexer) index(user string) error {
151151
"user": user,
152152
})
153153

154-
cutoff := time.Now().Add(time.Hour * -12)
154+
pageCutoff := time.Now().Add(-12 * time.Hour)
155+
cutoff := time.Now().Add(-14 * 24 * time.Hour)
155156
activity := []Activity(nil)
156157

157158
for page := ""; ; {
@@ -163,20 +164,23 @@ func (indexer *RedditIndexer) index(user string) error {
163164

164165
done := len(things) == 0
165166
for _, thing := range things {
166-
if thing.ActivityTime().Before(cutoff) {
167+
if thing.ActivityTime().Before(pageCutoff) {
167168
done = true
168169
}
170+
if thing.ActivityTime().Before(cutoff) {
171+
break
172+
}
169173
activity = append(activity, thing)
170174
}
171175

172176
logger.WithFields(log.Fields{
173-
"count": len(things),
177+
"count": len(activity),
174178
}).Info("received reddit activity")
175179

176180
if done {
177181
break
178182
}
179-
time.Sleep(time.Second * 2)
183+
time.Sleep(time.Second * 3)
180184
}
181185

182186
if len(activity) == 0 {

0 commit comments

Comments
 (0)