def _add_message_nolock(key, message): from r2.models import Account, Message trees = g.permacache.get(key) if not trees: # in case an empty list got written at some point, delete it to # force a recompute if trees is not None: g.permacache.delete(key) # no point computing it now. We'll do it when they go to # their message page. return # if it is a new root message, easy enough if message.first_message is None: trees.insert(0, (message._id, [])) else: tree_dict = dict(trees) # if the tree already has the first message, update the list if message.first_message in tree_dict: if message._id not in tree_dict[message.first_message]: tree_dict[message.first_message].append(message._id) tree_dict[message.first_message].sort() # we have to regenerate the conversation :/ else: m = Message._query( Message.c.first_message == message.first_message, data=True) new_tree = compute_message_trees(m) if new_tree: trees.append(new_tree[0]) trees.sort(key=tree_sort_fn, reverse=True) # done! g.permacache.set(key, trees)
def _add_message_nolock(key, message): from r2.models import Account, Message trees = g.permacache.get(key) if not trees: # in case an empty list got written at some point, delete it to # force a recompute if trees is not None: g.permacache.delete(key) # no point computing it now. We'll do it when they go to # their message page. return # if it is a new root message, easy enough if message.first_message is None: trees.insert(0, (message._id, [])) else: tree_dict = dict(trees) # if the tree already has the first message, update the list if message.first_message in tree_dict: if message._id not in tree_dict[message.first_message]: tree_dict[message.first_message].append(message._id) tree_dict[message.first_message].sort() # we have to regenerate the conversation :/ else: m = Message._query(Message.c.first_message == message.first_message, data = True) new_tree = compute_message_trees(m) if new_tree: trees.append(new_tree[0]) trees.sort(key = tree_sort_fn, reverse = True) # done! g.permacache.set(key, trees)
def _conversation(trees, parent): from r2.models import Message if parent._id in trees: convo = trees[parent._id] if convo: m = Message._byID(convo[0], data=True) if not convo or m.first_message == m.parent_id: return [(parent._id, convo)] # if we get to this point, either we didn't find the conversation, # or the first child of the result was not the actual first child. # To the database! m = Message._query(Message.c.first_message == parent._id, data=True) return compute_message_trees([parent] + list(m))
def _conversation(trees, parent): from r2.models import Message if parent._id in trees: convo = trees[parent._id] if convo: m = Message._byID(convo[0], data=True) if not convo or m.first_message == m.parent_id: return [(parent._id, convo)] # if we get to this point, either we didn't find the conversation, # or the first child of the result was not the actual first child. # To the database! rules = [Message.c.first_message == parent._id] if c.user_is_admin: rules.append(Message.c._spam == (True, False)) rules.append(Message.c._deleted == (True, False)) m = Message._query(*rules, data=True) return compute_message_trees([parent] + list(m))
def _conversation(trees, parent): from r2.models import Message if parent._id in trees: convo = trees[parent._id] if convo: m = Message._byID(convo[0], data = True) if not convo or m.first_message == m.parent_id: return [(parent._id, convo)] # if we get to this point, either we didn't find the conversation, # or the first child of the result was not the actual first child. # To the database! rules = [Message.c.first_message == parent._id] if c.user_is_admin: rules.append(Message.c._spam == (True, False)) rules.append(Message.c._deleted == (True, False)) m = Message._query(*rules, data=True) return compute_message_trees([parent] + list(m))
def get_sent(user): q = Message._query(Message.c.author_id == user._id, Message.c._spam == (True, False), sort = desc('_date')) return make_results(q)
def get_sent(user): q = Message._query(Message.c.author_id == user._id, Message.c._spam == (True, False), sort=desc('_date')) return make_results(q)
def get_sent(user_id): return Message._query(Message.c.author_id == user_id, Message.c._spam == (True, False), sort = desc('_date'))