replace MultiSubscriber with TimelineSub

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-16 12:47:31 -04:00
parent 64ac06791a
commit 6544d43d02
3 changed files with 257 additions and 182 deletions

View File

@@ -1,7 +1,6 @@
use crate::{
actionbar::TimelineOpenResult,
error::Error,
multi_subscriber::MultiSubscriber,
//subscriptions::SubRefs,
timeline::{Timeline, TimelineKind},
};
@@ -55,20 +54,17 @@ impl TimelineCache {
return Err(Error::TimelineNotFound);
};
if let Some(sub) = &mut timeline.subscription {
// if this is the last subscriber, remove the timeline from cache
if sub.unsubscribe(ndb, pool) {
debug!(
"popped last timeline {:?}, removing from timeline cache",
id
);
self.timelines.remove(id);
}
timeline.subscription.unsubscribe_or_decrement(ndb, pool);
Ok(())
} else {
Err(Error::MissingSubscription)
if timeline.subscription.no_sub() {
debug!(
"popped last timeline {:?}, removing from timeline cache",
id
);
self.timelines.remove(id);
}
Ok(())
}
fn get_expected_mut(&mut self, key: &TimelineKind) -> &mut Timeline {
@@ -158,7 +154,7 @@ impl TimelineCache {
// The timeline cache is stale, let's update it
let notes = find_new_notes(
timeline.all_or_any_notes(),
timeline.subscription.as_ref().map(|s| &s.filters)?,
timeline.subscription.get_filter()?,
txn,
ndb,
);
@@ -180,14 +176,10 @@ impl TimelineCache {
Vitality::Fresh(timeline) => (None, timeline),
};
if let Some(multi_sub) = &mut timeline.subscription {
debug!("got open with *old* subscription for {:?}", &timeline.kind);
multi_sub.subscribe(ndb, pool);
} else if let Some(filter) = timeline.filter.get_any_ready() {
if let Some(filter) = timeline.filter.get_any_ready() {
debug!("got open with *new* subscription for {:?}", &timeline.kind);
let mut multi_sub = MultiSubscriber::new(filter.clone());
multi_sub.subscribe(ndb, pool);
timeline.subscription = Some(multi_sub);
timeline.subscription.try_add_local(ndb, filter);
timeline.subscription.try_add_remote(pool, filter);
} else {
// This should never happen reasoning, self.notes would have
// failed above if the filter wasn't ready

View File

@@ -1,6 +1,6 @@
use crate::{
error::Error,
multi_subscriber::MultiSubscriber,
multi_subscriber::TimelineSub,
subscriptions::{self, SubKind, Subscriptions},
timeline::kind::ListKind,
Result,
@@ -198,7 +198,7 @@ pub struct Timeline {
pub views: Vec<TimelineTab>,
pub selected_view: usize,
pub subscription: Option<MultiSubscriber>,
pub subscription: TimelineSub,
}
impl Timeline {
@@ -257,7 +257,7 @@ impl Timeline {
pub fn new(kind: TimelineKind, filter_state: FilterState, views: Vec<TimelineTab>) -> Self {
let filter = FilterStates::new(filter_state);
let subscription: Option<MultiSubscriber> = None;
let subscription = TimelineSub::default();
let selected_view = 0;
Timeline {
@@ -405,8 +405,7 @@ impl Timeline {
let sub = self
.subscription
.as_ref()
.and_then(|s| s.local_subid)
.get_local()
.ok_or(Error::App(notedeck::Error::no_active_sub()))?;
let new_note_ids = ndb.poll_for_notes(sub, 500);
@@ -613,19 +612,7 @@ fn setup_initial_timeline(
) -> Result<()> {
// some timelines are one-shot and a refreshed, like last_per_pubkey algo feed
if timeline.kind.should_subscribe_locally() {
let local_sub = ndb.subscribe(filters)?;
match &mut timeline.subscription {
None => {
timeline.subscription = Some(MultiSubscriber::with_initial_local_sub(
local_sub,
filters.to_vec(),
));
}
Some(msub) => {
msub.local_subid = Some(local_sub);
}
};
timeline.subscription.try_add_local(ndb, filters);
}
debug!(