Make activity limit in outbox fetcher adjustable

This commit is contained in:
silverpill 2023-04-12 23:37:53 +00:00 committed by Rafael Caricio
parent a3f44cf678
commit e2ea58d33a
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
4 changed files with 8 additions and 5 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed ### Changed
- Ignore errors when importing activities from outbox. - Ignore errors when importing activities from outbox.
- Make activity limit in outbox fetcher adjustable.
## [1.21.0] - 2023-04-12 ## [1.21.0] - 2023-04-12

View file

@ -227,6 +227,8 @@ impl RefetchActor {
#[derive(Parser)] #[derive(Parser)]
pub struct ReadOutbox { pub struct ReadOutbox {
actor_id: String, actor_id: String,
#[clap(long, default_value_t = 5)]
limit: usize,
} }
impl ReadOutbox { impl ReadOutbox {
@ -235,7 +237,7 @@ impl ReadOutbox {
config: &Config, config: &Config,
db_client: &mut impl DatabaseClient, db_client: &mut impl DatabaseClient,
) -> Result<(), Error> { ) -> Result<(), Error> {
import_from_outbox(config, db_client, &self.actor_id).await?; import_from_outbox(config, db_client, &self.actor_id, self.limit).await?;
Ok(()) Ok(())
} }
} }

View file

@ -228,11 +228,10 @@ pub async fn fetch_object(
Ok(object) Ok(object)
} }
const OUTBOX_PAGE_SIZE_LIMIT: usize = 5;
pub async fn fetch_outbox( pub async fn fetch_outbox(
instance: &Instance, instance: &Instance,
outbox_url: &str, outbox_url: &str,
limit: usize,
) -> Result<Vec<JsonValue>, FetchError> { ) -> Result<Vec<JsonValue>, FetchError> {
#[derive(Deserialize)] #[derive(Deserialize)]
struct Collection { struct Collection {
@ -248,6 +247,6 @@ pub async fn fetch_outbox(
let page_json = send_request(instance, &collection.first).await?; let page_json = send_request(instance, &collection.first).await?;
let page: CollectionPage = serde_json::from_str(&page_json)?; let page: CollectionPage = serde_json::from_str(&page_json)?;
let activities = page.ordered_items.into_iter() let activities = page.ordered_items.into_iter()
.take(OUTBOX_PAGE_SIZE_LIMIT).collect(); .take(limit).collect();
Ok(activities) Ok(activities)
} }

View file

@ -307,10 +307,11 @@ pub async fn import_from_outbox(
config: &Config, config: &Config,
db_client: &mut impl DatabaseClient, db_client: &mut impl DatabaseClient,
actor_id: &str, actor_id: &str,
limit: usize,
) -> Result<(), HandlerError> { ) -> Result<(), HandlerError> {
let instance = config.instance(); let instance = config.instance();
let actor = fetch_actor(&instance, actor_id).await?; let actor = fetch_actor(&instance, actor_id).await?;
let activities = fetch_outbox(&instance, &actor.outbox).await?; let activities = fetch_outbox(&instance, &actor.outbox, limit).await?;
log::info!("fetched {} activities", activities.len()); log::info!("fetched {} activities", activities.len());
for activity in activities { for activity in activities {
let activity_actor = activity["actor"].as_str() let activity_actor = activity["actor"].as_str()