| @@ -381,56 +381,13 @@ func (s *Server) syncUserInBackground(userDID string, client *atproto.Client) { |
| 381 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | 381 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) |
| 382 | defer cancel() | 382 | defer cancel() |
| 383 | | 383 | |
| 384 | - isNewUser := false | | |
| 385 | - if count, err := s.dbs.Articles.GetSubscriptionCount(ctx, userDID); err == nil && count == 0 { | | |
| 386 | - isNewUser = true | | |
| 387 | - } | | |
| 388 | - | | |
| 389 | sync := atproto.NewSync(s.dbs.Articles, s.dbs.Users, client, s.logger) | 384 | sync := atproto.NewSync(s.dbs.Articles, s.dbs.Users, client, s.logger) |
| 390 | if err := sync.Run(ctx, userDID); err != nil { | 385 | if err := sync.Run(ctx, userDID); err != nil { |
| 391 | s.logger.Error("background sync failed", "error", err, "did", userDID) | 386 | s.logger.Error("background sync failed", "error", err, "did", userDID) |
| 392 | } | 387 | } |
| 393 | - | | |
| 394 | - if isNewUser { | | |
| 395 | - s.refreshUserFeeds(ctx, userDID) | | |
| 396 | - } | | |
| 397 | }() | 388 | }() |
| 398 | } | 389 | } |
| 399 | | 390 | |
| 400 | -func (s *Server) refreshUserFeeds(ctx context.Context, userDID string) { | | |
| 401 | - subs, err := s.dbs.Articles.ListSubscriptions(ctx, userDID, "", 1000, 0) | | |
| 402 | - if err != nil { | | |
| 403 | - s.logger.Error("failed to list subscriptions for initial fetch", "error", err, "did", userDID) | | |
| 404 | - return | | |
| 405 | - } | | |
| 406 | - | | |
| 407 | - // Fetch each feed once, even if many users subscribe to the same feed. | | |
| 408 | - // Dead feeds (error_count >= 25) are intentionally retried here so a new | | |
| 409 | - // user's subscriptions get a chance to succeed before being gated by the | | |
| 410 | - // scheduler's error_count filter. | | |
| 411 | - seen := make(map[string]bool, len(subs)) | | |
| 412 | - for _, sub := range subs { | | |
| 413 | - if seen[sub.FeedURL] { | | |
| 414 | - continue | | |
| 415 | - } | | |
| 416 | - seen[sub.FeedURL] = true | | |
| 417 | - | | |
| 418 | - f, err := s.dbs.Articles.GetFeed(ctx, sub.FeedURL) | | |
| 419 | - if err != nil { | | |
| 420 | - continue | | |
| 421 | - } | | |
| 422 | - s.scheduler.FetchFeed(ctx, &feed.Feed{ | | |
| 423 | - URL: f.FeedURL, | | |
| 424 | - Title: f.Title.String, | | |
| 425 | - SiteURL: f.SiteURL.String, | | |
| 426 | - Description: f.Description.String, | | |
| 427 | - Type: f.FeedType.String, | | |
| 428 | - ETag: f.Etag.String, | | |
| 429 | - LastModified: f.LastModified.String, | | |
| 430 | - }) | | |
| 431 | - } | | |
| 432 | -} | | |
| 433 | - | | |
| 434 | func (s *Server) PeriodicSync(ctx context.Context, interval time.Duration) { | 391 | func (s *Server) PeriodicSync(ctx context.Context, interval time.Duration) { |
| 435 | ticker := time.NewTicker(interval) | 392 | ticker := time.NewTicker(interval) |
| 436 | defer ticker.Stop() | 393 | defer ticker.Stop() |