* Mark instance as alive after successful activity send (fixes #4039) * clippy * Instance::update * domain --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
parent
1be7dbde33
commit
b58da11fb7
3 changed files with 29 additions and 8 deletions
|
@ -64,6 +64,18 @@ impl Instance {
|
|||
e => e,
|
||||
}
|
||||
}
|
||||
pub async fn update(
|
||||
pool: &mut DbPool<'_>,
|
||||
instance_id: InstanceId,
|
||||
form: InstanceForm,
|
||||
) -> Result<usize, Error> {
|
||||
let mut conn = get_conn(pool).await?;
|
||||
diesel::update(instance::table.find(instance_id))
|
||||
.set(form)
|
||||
.execute(&mut conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete(pool: &mut DbPool<'_>, instance_id: InstanceId) -> Result<usize, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::delete(instance::table.find(instance_id))
|
||||
|
|
|
@ -11,7 +11,7 @@ use activitypub_federation::{
|
|||
protocol::context::WithContext,
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use chrono::{DateTime, Days, TimeZone, Utc};
|
||||
use lemmy_api_common::{context::LemmyContext, federate_retry_sleep_duration};
|
||||
use lemmy_apub::{activity_lists::SharedInboxActivities, FEDERATION_CONTEXT};
|
||||
use lemmy_db_schema::{
|
||||
|
@ -19,17 +19,17 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
activity::SentActivity,
|
||||
federation_queue_state::FederationQueueState,
|
||||
instance::Instance,
|
||||
instance::{Instance, InstanceForm},
|
||||
site::Site,
|
||||
},
|
||||
utils::DbPool,
|
||||
utils::{naive_now, DbPool},
|
||||
};
|
||||
use lemmy_db_views_actor::structs::CommunityFollowerView;
|
||||
use once_cell::sync::Lazy;
|
||||
use reqwest::Url;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
ops::Deref,
|
||||
ops::{Add, Deref},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::{sync::mpsc::UnboundedSender, time::sleep};
|
||||
|
@ -257,6 +257,18 @@ impl InstanceWorker {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Activity send successful, mark instance as alive if it hasn't been updated in a while.
|
||||
let updated = self.instance.updated.unwrap_or(self.instance.published);
|
||||
if updated.add(Days::new(1)) < Utc::now() {
|
||||
self.instance.updated = Some(Utc::now());
|
||||
|
||||
let form = InstanceForm::builder()
|
||||
.domain(self.instance.domain.clone())
|
||||
.updated(Some(naive_now()))
|
||||
.build();
|
||||
Instance::update(pool, self.instance.id, form).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -495,10 +495,7 @@ async fn update_instance_software(
|
|||
}
|
||||
};
|
||||
if let Some(form) = form {
|
||||
diesel::update(instance::table.find(instance.id))
|
||||
.set(form)
|
||||
.execute(&mut conn)
|
||||
.await?;
|
||||
Instance::update(pool, instance.id, form).await?;
|
||||
}
|
||||
}
|
||||
info!("Finished updating instances software and versions...");
|
||||
|
|
Loading…
Reference in a new issue