mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Merge pull request 'Change criteria for restricting available cross posts' (#420) from change_xp_restrictions into main
Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/420
This commit is contained in:
commit
242c737076
2 changed files with 17 additions and 20 deletions
|
@ -199,7 +199,7 @@ def retrieve_mods_and_backfill(community_id: int):
|
||||||
post.ap_announce_id = activity['id']
|
post.ap_announce_id = activity['id']
|
||||||
post.ranking = post.post_ranking(post.score, post.posted_at)
|
post.ranking = post.post_ranking(post.score, post.posted_at)
|
||||||
if post.url:
|
if post.url:
|
||||||
post.calculate_cross_posts(backfilled=True)
|
post.calculate_cross_posts()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
activity_log.exception_message = 'Could not find or create actor'
|
activity_log.exception_message = 'Could not find or create actor'
|
||||||
|
|
|
@ -1413,7 +1413,7 @@ class Post(db.Model):
|
||||||
td = date - self.epoch
|
td = date - self.epoch
|
||||||
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
|
return td.days * 86400 + td.seconds + (float(td.microseconds) / 1000000)
|
||||||
|
|
||||||
def calculate_cross_posts(self, delete_only=False, url_changed=False, backfilled=False):
|
def calculate_cross_posts(self, delete_only=False, url_changed=False):
|
||||||
if not self.url and not delete_only:
|
if not self.url and not delete_only:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -1421,11 +1421,11 @@ class Post(db.Model):
|
||||||
old_cross_posts = Post.query.filter(Post.id.in_(self.cross_posts)).all()
|
old_cross_posts = Post.query.filter(Post.id.in_(self.cross_posts)).all()
|
||||||
self.cross_posts.clear()
|
self.cross_posts.clear()
|
||||||
for ocp in old_cross_posts:
|
for ocp in old_cross_posts:
|
||||||
if ocp.cross_posts is not None:
|
if ocp.cross_posts and self.id in ocp.cross_posts:
|
||||||
ocp.cross_posts.remove(self.id)
|
ocp.cross_posts.remove(self.id)
|
||||||
|
|
||||||
if delete_only:
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
if delete_only:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.url.count('/') < 3 or (self.url.count('/') == 3 and self.url.endswith('/')):
|
if self.url.count('/') < 3 or (self.url.count('/') == 3 and self.url.endswith('/')):
|
||||||
|
@ -1436,22 +1436,19 @@ class Post(db.Model):
|
||||||
# daily posts to this community (e.g. to https://travle.earth/usa or https://www.nytimes.com/games/wordle/index.html) shouldn't be treated as cross-posts
|
# daily posts to this community (e.g. to https://travle.earth/usa or https://www.nytimes.com/games/wordle/index.html) shouldn't be treated as cross-posts
|
||||||
return
|
return
|
||||||
|
|
||||||
if not backfilled:
|
limit = 9
|
||||||
new_cross_posts = Post.query.filter(Post.id != self.id, Post.url == self.url, Post.deleted == False,
|
new_cross_posts = Post.query.filter(Post.id != self.id, Post.url == self.url, Post.deleted == False).order_by(desc(Post.id)).limit(limit)
|
||||||
Post.posted_at > self.posted_at - timedelta(days=6))
|
|
||||||
else:
|
# other posts: update their cross_posts field with this post.id if they have less than the limit
|
||||||
new_cross_posts = Post.query.filter(Post.id != self.id, Post.url == self.url, Post.deleted == False,
|
for ncp in new_cross_posts:
|
||||||
Post.posted_at > self.posted_at - timedelta(days=3),
|
if ncp.cross_posts is None:
|
||||||
Post.posted_at < self.posted_at + timedelta(days=3))
|
ncp.cross_posts = [self.id]
|
||||||
for op in new_cross_posts:
|
elif len(ncp.cross_posts) < limit:
|
||||||
if op.cross_posts is None:
|
ncp.cross_posts.append(self.id)
|
||||||
op.cross_posts = [self.id]
|
|
||||||
else:
|
# this post: set the cross_posts field to the limited list of ids from the most recent other posts
|
||||||
op.cross_posts.append(self.id)
|
if new_cross_posts:
|
||||||
if self.cross_posts is None:
|
self.cross_posts = [ncp.id for ncp in new_cross_posts]
|
||||||
self.cross_posts = [op.id]
|
|
||||||
else:
|
|
||||||
self.cross_posts.append(op.id)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def delete_dependencies(self):
|
def delete_dependencies(self):
|
||||||
|
|
Loading…
Reference in a new issue