mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Trim the message tree when it reaches a certain size.
This commit is contained in:
@@ -28,6 +28,7 @@ from r2.lib.cache import sgm
|
||||
from r2.models.comment_tree import CommentTree
|
||||
from r2.models.link import Comment, Link
|
||||
|
||||
MESSAGE_TREE_SIZE_LIMIT = 15000
|
||||
|
||||
def comments_key(link_id):
|
||||
return 'comments_' + str(link_id)
|
||||
@@ -272,6 +273,13 @@ def _add_message_nolock(key, message):
|
||||
trees.append(new_tree[0])
|
||||
trees.sort(key = tree_sort_fn, reverse = True)
|
||||
|
||||
# If we have too many messages in the tree, drop the oldest
|
||||
# conversation to avoid the permacache size limit
|
||||
tree_size = len(trees) + sum(len(convo[1]) for convo in trees)
|
||||
|
||||
if tree_size > MESSAGE_TREE_SIZE_LIMIT:
|
||||
del trees[-1]
|
||||
|
||||
# done!
|
||||
g.permacache.set(key, trees)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user