comparison MoinMoin/macro/PageHits.py @ 3467:d62fd466d810

macro.PageHits: fixes multiple call of PageHits (MoinMoinBugs/ClickOnNavibarIncreasesHitsByMultiplicator)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 04 Apr 2008 23:09:44 +0200
parents 1ad6243cdf06
children
comparison
equal deleted inserted replaced
3466:7bf716a48fc6 3467:d62fd466d810
42 return date, hits 42 return date, hits
43 43
44 def addHitsFromLog(self, hits, cacheDate): 44 def addHitsFromLog(self, hits, cacheDate):
45 """ Parse the log, add hits after cacheDate and update the cache """ 45 """ Parse the log, add hits after cacheDate and update the cache """
46 event_log = eventlog.EventLog(self.request) 46 event_log = eventlog.EventLog(self.request)
47 try: 47 event_log.set_filter(['VIEWPAGE'])
48 logDate = event_log.date()
49 except logfile.LogMissing:
50 return
51 48
52 changed = False 49 changed = False
53 event_log.set_filter(['VIEWPAGE']) 50 # don't use event_log.date()
51 latest = None
54 for event in event_log.reverse(): 52 for event in event_log.reverse():
53 if latest is None:
54 latest = event[0]
55 if event[0] <= cacheDate: 55 if event[0] <= cacheDate:
56 break 56 break
57 page = event[2].get('pagename', None) 57 page = event[2].get('pagename', None)
58 if page: 58 if page:
59 hits[page] = hits.get(page, 0) + 1 59 hits[page] = hits.get(page, 0) + 1
60 changed = True 60 changed = True
61 61
62 if changed: 62 if changed:
63 self.updateCache(logDate, hits) 63 self.updateCache(latest, hits)
64 64
65 def updateCache(self, date, hits): 65 def updateCache(self, date, hits):
66 try: 66 try:
67 self.cache.update((date, hits)) 67 self.cache.update((date, hits))
68 except caching.CacheError: 68 except caching.CacheError: