fix: don't fetch while inserting, just give up

because we insert while fetching ehehe so basically if we can't figure
out the context we set it to None and we'll have to do it another time.
we cant trust mastodon because it doesnt produce reliable contexts and
misskeys just dont use contexts at all (wtf!!!)
This commit is contained in:
əlemi 2024-05-24 00:21:02 +02:00
parent 34c01dd858
commit 79236699cc
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -31,15 +31,20 @@ impl Normalizer for super::Context {
object_model.content = Some(mdhtml::safe_html(&content)); object_model.content = Some(mdhtml::safe_html(&content));
} }
// fix context also for remote posts // fix context for remote posts
// TODO this is not really appropriate because we're mirroring incorrectly remote objects, but // > note that this will effectively recursively try to fetch the parent object, in order to find
// it makes it SOO MUCH EASIER for us to fetch threads and stuff, so we're filling it for them // > the context (which is id of topmost object). there's a recursion limit of 16 hidden inside
match (&object_model.in_reply_to, &object_model.context) { // > btw! also if any link is broken or we get rate limited, the whole insertion fails which is
(Some(reply_id), None) => // get context from replied object // > kind of dumb. there should be a job system so this can be done in waves. or maybe there's
object_model.context = self.fetch_object(reply_id).await?.context, // > some whole other way to do this?? im thinking but misskey aaaa!! TODO
(None, None) => // generate a new context if let Some(ref reply) = object_model.in_reply_to {
object_model.context = Some(object_model.id.clone()), if let Some(o) = model::object::Entity::find_by_id(reply).one(self.db()).await? {
(_, Some(_)) => {}, // leave it as set by user object_model.context = o.context;
} else {
object_model.context = None; // TODO to be filled by some other task
}
} else {
object_model.context = Some(object_model.id.clone());
} }
model::object::Entity::insert(object_model.clone().into_active_model()).exec(self.db()).await?; model::object::Entity::insert(object_model.clone().into_active_model()).exec(self.db()).await?;