mirror of https://github.com/LemmyNet/lemmy
start federation based on latest id at the time
parent
c654ceeb06
commit
284ebb3304
|
@ -17,7 +17,7 @@ pub struct FederationQueueState {
|
|||
}
|
||||
|
||||
impl FederationQueueState {
|
||||
/// load or return a default empty value
|
||||
/// load state or return a default empty value
|
||||
pub async fn load(pool: &mut DbPool<'_>, domain_: &str) -> Result<FederationQueueState> {
|
||||
use lemmy_db_schema::schema::federation_queue_state::dsl::{domain, federation_queue_state};
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
@ -32,7 +32,7 @@ impl FederationQueueState {
|
|||
domain: domain_.to_owned(),
|
||||
fail_count: 0,
|
||||
last_retry: Utc.timestamp_nanos(0),
|
||||
last_successful_id: 0, // todo: start at current id not from beginning
|
||||
last_successful_id: 0, // this value is set to the most current id for new instances
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -105,6 +105,13 @@ impl InstanceWorker {
|
|||
}
|
||||
async fn loop_batch(&mut self, pool: &mut DbPool<'_>) -> Result<()> {
|
||||
let latest_id = get_latest_activity_id(pool).await?;
|
||||
if self.state.last_successful_id == 0 {
|
||||
// this is the initial creation (instance first seen) of the federation queue for this instance
|
||||
// skip all past activities:
|
||||
self.state.last_successful_id = latest_id;
|
||||
// save here to ensure it's not read as 0 again later if no activities have happened
|
||||
self.save_and_send_state(pool).await?;
|
||||
}
|
||||
let mut id = self.state.last_successful_id;
|
||||
if id == latest_id {
|
||||
// no more work to be done, wait before rechecking
|
||||
|
|
Loading…
Reference in New Issue