fix: also update comments count when fetching

This commit is contained in:
əlemi 2024-04-29 21:22:48 +02:00
parent 35804730de
commit 3e0e4ff8d3
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use apb::{target::Addressed, Activity, Object}; use apb::{target::Addressed, Activity, Object};
use base64::Engine; use base64::Engine;
use reqwest::{header::{ACCEPT, CONTENT_TYPE, USER_AGENT}, Method, Response}; use reqwest::{header::{ACCEPT, CONTENT_TYPE, USER_AGENT}, Method, Response};
use sea_orm::{EntityTrait, IntoActiveModel}; use sea_orm::{sea_query::Expr, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};
use crate::{model, VERSION}; use crate::{model, VERSION};
@ -155,6 +155,11 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
if let Some(reply) = &object_model.in_reply_to { if let Some(reply) = &object_model.in_reply_to {
if depth <= 16 { if depth <= 16 {
fetch_object_inner(ctx, reply, depth + 1).await?; fetch_object_inner(ctx, reply, depth + 1).await?;
model::object::Entity::update_many()
.filter(model::object::Column::Id.eq(reply))
.col_expr(model::object::Column::Comments, Expr::col(model::object::Column::Comments).add(1))
.exec(ctx.db())
.await?;
} else { } else {
tracing::warn!("thread deeper than 16, giving up fetching more replies"); tracing::warn!("thread deeper than 16, giving up fetching more replies");
} }