blob: 62edb5dc9ec2cf3aadf190548e1a428bca30ea49 (
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
39
40
|
# -*- 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 num, thread in enumerate(store.db.find(Thread)):
thread.emails_count = None # reset it
len(thread) # this will refill the cached value
thread.participants_count = len(thread.participants)
if num % 1000 == 0:
store.commit() # otherwise we'll blow up the memory
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)
|