replace ToMinionPayloadDetail::SubscribeGeneralFeed & TempSubscribeGeneralFeedChunk

This commit is contained in:
Mike Dilger 2024-08-18 22:10:32 +12:00
parent 996e2e3b28
commit d6b0fccba1
4 changed files with 25 additions and 122 deletions

View File

@ -265,7 +265,6 @@ pub(crate) enum ToMinionPayloadDetail {
Shutdown,
Subscribe(FilterSet),
Unsubscribe(FilterSet),
SubscribeGeneralFeed(Vec<PublicKey>, Unixtime),
SubscribeGiftwraps(Unixtime),
SubscribeGlobalFeed(Unixtime),
SubscribeInbox(Unixtime),
@ -274,14 +273,7 @@ pub(crate) enum ToMinionPayloadDetail {
SubscribeRootReplies(EventReference),
SubscribeDmChannel(DmChannel),
SubscribeNip46,
TempSubscribeGeneralFeedChunk {
pubkeys: Vec<PublicKey>,
anchor: Unixtime,
},
TempSubscribePersonFeedChunk {
pubkey: PublicKey,
anchor: Unixtime,
},
TempSubscribePersonFeedChunk { pubkey: PublicKey, anchor: Unixtime },
TempSubscribeInboxFeedChunk(Unixtime),
TempSubscribeMetadata(Vec<PublicKey>),
UnsubscribeGlobalFeed,

View File

@ -3,33 +3,6 @@ use crate::filter_set::FeedRange;
use crate::globals::GLOBALS;
use nostr_types::{EventKind, Filter, IdHex, NAddr, PublicKey, PublicKeyHex, Tag, Unixtime};
pub fn general_feed(authors: &[PublicKey], range: FeedRange) -> Vec<Filter> {
let mut filters: Vec<Filter> = Vec::new();
if authors.is_empty() {
return vec![];
}
let pkp: Vec<PublicKeyHex> = authors.iter().map(|pk| pk.into()).collect();
// Do not load feed related event kinds, or the limit will be wrong
let event_kinds = crate::feed::feed_displayable_event_kinds(false);
let (since, until, limit) = range.since_until_limit();
// feed related by people followed
filters.push(Filter {
authors: pkp,
kinds: event_kinds.clone(),
since,
until,
limit,
..Default::default()
});
filters
}
pub fn inbox_feed(spamsafe: bool, range: FeedRange) -> Vec<Filter> {
let mut filters: Vec<Filter> = Vec::new();

View File

@ -637,10 +637,6 @@ impl Minion {
self.unsubscribe(&handle).await?;
}
}
ToMinionPayloadDetail::SubscribeGeneralFeed(pubkeys, anchor) => {
self.subscribe_general_feed(message.job_id, pubkeys, anchor)
.await?;
}
ToMinionPayloadDetail::SubscribeInbox(anchor) => {
self.subscribe_inbox(message.job_id, anchor).await?;
}
@ -666,10 +662,6 @@ impl Minion {
ToMinionPayloadDetail::SubscribeNip46 => {
self.subscribe_nip46(message.job_id).await?;
}
ToMinionPayloadDetail::TempSubscribeGeneralFeedChunk { pubkeys, anchor } => {
self.temp_subscribe_general_feed_chunk(message.job_id, pubkeys, anchor)
.await?;
}
ToMinionPayloadDetail::TempSubscribePersonFeedChunk { pubkey, anchor } => {
self.temp_subscribe_person_feed_chunk(message.job_id, pubkey, anchor)
.await?;
@ -697,39 +689,6 @@ impl Minion {
Ok(())
}
// Subscribe to the user's followers on the relays they write to
async fn subscribe_general_feed(
&mut self,
job_id: u64,
pubkeys: Vec<PublicKey>,
anchor: Unixtime,
) -> Result<(), Error> {
tracing::debug!("Following {} people at {}", pubkeys.len(), &self.url);
let limit = GLOBALS.storage.read_setting_load_more_count() as usize;
let mut filters = filter_fns::general_feed(&pubkeys, FeedRange::After { since: anchor });
let filters2 = filter_fns::general_feed(
&pubkeys,
FeedRange::ChunkBefore {
until: anchor,
limit,
},
);
filters.extend(filters2);
if filters.is_empty() {
self.unsubscribe("general_feed").await?;
self.to_overlord.send(ToOverlordMessage::MinionJobComplete(
self.url.clone(),
job_id,
))?;
} else {
self.subscribe(filters, "general_feed", job_id).await?;
}
Ok(())
}
async fn subscribe_giftwraps(&mut self, job_id: u64, after: Unixtime) -> Result<(), Error> {
// If we have already subscribed to giftwraps, do not resubscribe
if self.subscription_map.has("giftwraps") {
@ -1096,37 +1055,6 @@ impl Minion {
self.subscribe(vec![filter], &handle, job_id).await
}
// Load more, one more chunk back
async fn temp_subscribe_general_feed_chunk(
&mut self,
job_id: u64,
pubkeys: Vec<PublicKey>,
anchor: Unixtime,
) -> Result<(), Error> {
let limit = GLOBALS.storage.read_setting_load_more_count() as usize;
let filters = filter_fns::general_feed(
&pubkeys,
FeedRange::ChunkBefore {
until: anchor,
limit,
},
);
if !filters.is_empty() {
// We include the job_id so that if the user presses "load more" yet again,
// the new chunk subscription doesn't clobber this subscription which might
// not have run to completion yet.
let sub_name = format!("temp_general_feed_chunk_{}", job_id);
if !self.initial_handling {
self.loading_more += 1;
let _ = GLOBALS.loading_more.fetch_add(1, Ordering::SeqCst);
}
self.subscribe(filters, &sub_name, job_id).await?;
}
Ok(())
}
async fn temp_subscribe_metadata(
&mut self,
job_id: u64,

View File

@ -326,16 +326,28 @@ impl Overlord {
async fn apply_relay_assignment(&mut self, assignment: RelayAssignment) -> Result<(), Error> {
let anchor = GLOBALS.feed.current_anchor();
let mut jobs = vec![RelayJob {
reason: RelayConnectionReason::Follow,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeGeneralFeed(
assignment.pubkeys.clone(),
anchor,
),
let mut jobs = vec![
RelayJob {
reason: RelayConnectionReason::Follow,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::GeneralFeedFuture {
pubkeys: assignment.pubkeys.clone(),
anchor,
}),
},
},
}];
RelayJob {
reason: RelayConnectionReason::Follow,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::GeneralFeedChunk {
pubkeys: assignment.pubkeys.clone(),
anchor,
}),
},
},
];
// Until NIP-65 is in widespread use, we should listen to inbox
// of us on all these relays too
@ -1524,10 +1536,10 @@ impl Overlord {
target: relay_assignment.relay_url.as_str().to_owned(),
payload: ToMinionPayload {
job_id: 0,
detail: ToMinionPayloadDetail::TempSubscribeGeneralFeedChunk {
detail: ToMinionPayloadDetail::Subscribe(FilterSet::GeneralFeedChunk {
pubkeys: relay_assignment.pubkeys.clone(),
anchor,
},
}),
},
});
}
@ -2601,9 +2613,7 @@ impl Overlord {
reason: RelayConnectionReason::Discovery,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::Subscribe(
FilterSet::Discover(pubkeys.clone())
),
detail: ToMinionPayloadDetail::Subscribe(FilterSet::Discover(pubkeys.clone())),
},
}],
);