|
2 | 2 | package poll |
3 | 3 |
|
4 | 4 | import ( |
| 5 | + "advrider-notifier/pkg/notifier" |
5 | 6 | "context" |
6 | 7 | "fmt" |
7 | 8 | "log/slog" |
8 | 9 | "math" |
9 | 10 | "sync" |
10 | 11 | "time" |
11 | | - |
12 | | - "advrider-notifier/pkg/notifier" |
13 | 12 | ) |
14 | 13 |
|
15 | 14 | const maxPostsPerEmail = 10 // Safety limit: max posts to include in a single email |
@@ -278,12 +277,17 @@ func (m *Monitor) checkThreadForSubscribers( |
278 | 277 | // Update poll time and latest post time for this subscriber |
279 | 278 | m.updateSubscriberTimestamps(thread, now, latestPostTime, email, threadURL) |
280 | 279 |
|
281 | | - // First check for this subscriber - just record the latest post ID |
| 280 | + // First check for this subscriber - just record the latest post ID without notification |
282 | 281 | if thread.LastPostID == "" { |
283 | | - if m.saveInitialState(ctx, sub, email, info.threadID, threadURL, latestPost.ID, savedEmails) { |
284 | | - hasUpdates = true |
285 | | - } |
286 | | - continue |
| 282 | + thread.LastPostID = latestPost.ID |
| 283 | + m.logger.Info("New subscriber - recording initial state without notification", |
| 284 | + "cycle", m.cycleNumber, |
| 285 | + "email", email, |
| 286 | + "thread_url", threadURL, |
| 287 | + "thread_title", thread.ThreadTitle, |
| 288 | + "initial_post_id", latestPost.ID) |
| 289 | + m.saveStateNoNewPosts(ctx, sub, email, info.threadID, threadURL, savedEmails) |
| 290 | + continue // Move to next subscriber (other subscribers will still be notified) |
287 | 291 | } |
288 | 292 |
|
289 | 293 | // Find new posts for this subscriber |
@@ -395,49 +399,6 @@ func (m *Monitor) updateSubscriberTimestamps(thread *notifier.Thread, now, lates |
395 | 399 | } |
396 | 400 | } |
397 | 401 |
|
398 | | -// saveInitialState saves the initial state for a new subscriber. |
399 | | -func (m *Monitor) saveInitialState( |
400 | | - ctx context.Context, |
401 | | - sub *notifier.Subscription, |
402 | | - email, threadID, threadURL, postID string, |
403 | | - savedEmails map[string]bool, |
404 | | -) bool { |
405 | | - thread := sub.Threads[threadID] |
406 | | - if thread == nil { |
407 | | - m.logger.Error("CRITICAL: Thread not found when saving initial state - data corruption", |
408 | | - "cycle", m.cycleNumber, |
409 | | - "email", email, |
410 | | - "thread_id", threadID, |
411 | | - "thread_url", threadURL) |
412 | | - return false |
413 | | - } |
414 | | - thread.LastPostID = postID |
415 | | - |
416 | | - m.logger.Info("Saving initial state for subscriber", |
417 | | - "cycle", m.cycleNumber, |
418 | | - "email", email, |
419 | | - "thread_url", threadURL, |
420 | | - "post_id", postID) |
421 | | - |
422 | | - if err := m.store.Save(ctx, sub); err != nil { |
423 | | - m.logger.Error("Failed to save initial state for subscriber", |
424 | | - "cycle", m.cycleNumber, |
425 | | - "email", email, |
426 | | - "thread_url", threadURL, |
427 | | - "thread_title", thread.ThreadTitle, |
428 | | - "error", err) |
429 | | - } else { |
430 | | - savedEmails[email] = true |
431 | | - m.logger.Info("Initial post ID recorded and saved", |
432 | | - "cycle", m.cycleNumber, |
433 | | - "email", email, |
434 | | - "thread_url", threadURL, |
435 | | - "thread_title", thread.ThreadTitle, |
436 | | - "post_id", postID) |
437 | | - } |
438 | | - return true |
439 | | -} |
440 | | - |
441 | 402 | // findNewPosts identifies new posts for a subscriber since their last seen post. |
442 | 403 | func (m *Monitor) findNewPosts(posts []*notifier.Post, thread *notifier.Thread, email, threadURL string) []*notifier.Post { |
443 | 404 | var newPosts []*notifier.Post |
|
0 commit comments