Skip to content

Commit

Permalink
feat: notifications now filter addons for the AggrRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Lachezar Lechev <[email protected]>
  • Loading branch information
elpiel committed Jan 2, 2024
1 parent 43ab245 commit 3da7438
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/models/ctx/update_notifications.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{hash_map::Entry, HashMap};
use std::collections::{hash_map::Entry, HashMap, HashSet};

use chrono::Duration;
use either::Either;
Expand All @@ -20,7 +20,7 @@ use crate::{
Effect, EffectFuture, Effects, Env, EnvFutureExt,
},
types::{
addon::{AggrRequest, ExtraValue},
addon::{AggrRequest, ExtraType},
library::LibraryBucket,
notifications::{NotificationItem, NotificationsBucket},
profile::Profile,
Expand Down Expand Up @@ -72,12 +72,26 @@ pub fn update_notifications<E: Env + 'static>(
return Effects::none().unchanged();
}

let library_item_ids = library
let notifications_library_items = library
.items
.values()
.filter(|library_item| library_item.should_pull_notifications())
.sorted_by(|a, b| b.mtime.cmp(&a.mtime))
.take(NOTIFICATION_ITEMS_COUNT)
.cloned()
.collect::<Vec<_>>();

// all the types of the library items that are present in the list of LibraryItems that require notifications pulling
let library_item_types = notifications_library_items
.iter()
.map(|library_item| library_item.r#type.to_owned())
// deduplicate same types
.collect::<HashSet<_>>()
.into_iter()
.collect::<Vec<_>>();

let library_item_ids = notifications_library_items
.iter()
.map(|library_item| &library_item.id)
.cloned()
.collect::<Vec<_>>();
Expand All @@ -87,13 +101,11 @@ pub fn update_notifications<E: Env + 'static>(
notification_catalogs,
// force the making of a requests every time PullNotifications is called.
ResourcesAction::force_request(
&AggrRequest::AllCatalogs {
extra: &vec![ExtraValue {
name: LAST_VIDEOS_IDS_EXTRA_PROP.name.to_owned(),
value: library_item_ids.join(","),
}],
r#type: &None,
},
&AggrRequest::CatalogsFiltered(vec![ExtraType::Ids {
extra_name: LAST_VIDEOS_IDS_EXTRA_PROP.name.to_owned(),
ids: library_item_ids,
types: Some(library_item_types),
}]),
&profile.addons,
),
)
Expand Down

0 comments on commit 3da7438

Please sign in to comment.