mail based rss feed aggregator
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

have sender get all sent updates on startup and then only write to db

ollie 47caed6e 13f5ec6b

+24 -13
+24 -13
src/eater/sender.gleam
··· 345 345 registry: pubsub.Registry, 346 346 user: user.User, 347 347 feeds: List(rss.Location), 348 + updates_sent: List(String), 348 349 smtp_environment: smtp.SmtpEnvironment, 349 350 self: process.Subject(Message), 350 351 sending_failed_n_times: Int, ··· 367 368 ]) 368 369 369 370 // tell self to get this users feeds from the database 370 - process.send_after(self, 150, FetchFeeds) 371 + process.send_after(self, 150, InitFeeds) 371 372 372 373 let state = 373 374 State( ··· 375 376 registry:, 376 377 user:, 377 378 feeds: [], 379 + updates_sent: [], 378 380 smtp_environment:, 379 381 self:, 380 382 sending_failed_n_times: 0, ··· 401 403 pub opaque type Message { 402 404 /// sent once at the start to fetch all feeds 403 405 /// 404 - FetchFeeds 406 + InitFeeds 407 + /// sent once at the start after InitFeeds succeeds 408 + /// 409 + InitUpdatesSent 405 410 PubSubMessage(pubsub.Message) 406 411 Retry(message: pubsub.Message, attempt: Int) 407 412 ··· 424 429 ) 425 430 426 431 case message { 427 - FetchFeeds -> { 432 + // sent on startup 433 + InitFeeds -> { 428 434 case database.feeds_for_user(for: state.user, in: state.database) { 429 435 Ok(feeds) -> { 430 436 let state = 431 437 State(..state, feeds:) 432 438 |> initial_selector() 433 439 440 + actor.send(state.self, InitUpdatesSent) 441 + 434 442 actor.continue(state) 435 443 |> actor.with_selector(state.selector) 436 444 } 437 445 Error(_) -> actor.stop_abnormal("Failed to get feeds from the database") 446 + } 447 + } 448 + // sent on startup from InitFeeds /\ 449 + InitUpdatesSent -> { 450 + case database.updates_sent_to_user(state.database, state.user) { 451 + Ok(updates_sent) -> { 452 + let state = State(..state, updates_sent:) 453 + 454 + actor.continue(state) 455 + } 456 + Error(_) -> 457 + actor.stop_abnormal("Failed to get sent updates from the database") 438 458 } 439 459 } 440 460 PubSubMessage(pubsub.FeedUpdate(update:)) -> { ··· 659 679 state: State, 660 680 update: rss.FeedUpdate, 661 681 ) -> Result(Nil, FeedUpdateError) { 662 - use user_has_previously_received_item <- result.try( 663 - database.was_update_sent_to_user( 664 - user: state.user, 665 - item: update.new, 666 - database: state.database, 667 - ) 668 - |> result.map_error(FailedToCheckSentStatus), 669 - ) 670 - 671 682 use <- bool.guard( 672 - when: user_has_previously_received_item, 683 + when: list.contains(state.updates_sent, update.new.link), 673 684 return: Error(AlreadySent), 674 685 ) 675 686