blob: 1ec5600262b4db7abb42a88054d2c84d7ab14b60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# -*- coding: utf-8 -*-
"""
Cached values concerning threads
"""
from kittystore.caching import CachedValue
class ThreadStats(CachedValue):
"""Number of emails and number of participants"""
def on_new_message(self, store, mlist, message):
if message.thread.emails_count is None:
message.thread.emails_count = 1
else:
message.thread.emails_count += 1
message.thread.participants_count = \
len(message.thread.participants)
def refresh(self, store):
# XXX: Storm-specific
from kittystore.storm.model import Thread
for thread in store.db.find(Thread):
thread.emails_count = None # reset it
len(thread) # this will refill the cached value
thread.participants_count = len(thread.participants)
class ThreadSubject(CachedValue):
def on_new_thread(self, store, mlist, thread):
thread.subject = thread.starting_email.subject
def refresh(self, store):
# XXX: Storm-specific
from kittystore.storm.model import Thread
for thread in store.db.find(Thread, Thread.subject == None):
self.on_new_thread(store, None, thread)
|