Merge branch 'main' into revert-4321

revert-4321
Dessalines 2024-01-19 09:47:41 -05:00 committed by GitHub
commit fb599c32a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 8 deletions

View File

@ -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))

View File

@ -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(())
}

View File

@ -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...");