changeset 3424:aa3890b17212

macro.Hits: incredible speed up using MoinMoin.stats.hitcounts
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 28 Mar 2008 16:09:29 +0100
parents b9c90178b93a
children 1729bf752c83
files MoinMoin/macro/Hits.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/Hits.py	Sun Mar 23 13:18:03 2008 +0100
+++ b/MoinMoin/macro/Hits.py	Fri Mar 28 16:09:29 2008 +0100
@@ -15,17 +15,21 @@
                2005 BenjaminVrolijk
    @license: GNU GPL, see COPYING for details.
 """
-
 Dependencies = ['time'] # do not cache
 
-from MoinMoin.logfile import eventlog
+from MoinMoin.stats import hitcounts
 
 def macro_Hits(macro, all=False, event_type=(u'VIEWPAGE', u'SAVEPAGE')):
+    request = macro.request
     pagename = macro.formatter.page.page_name
-    event_log = eventlog.EventLog(macro.request)
-    if not all:
-        test = filter(lambda line: line[1] in event_type and line[2]['pagename'] == pagename, event_log)
+
+    if all:
+        cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=None)
     else:
-        test = filter(lambda line: line[1] in event_type, event_log)
+        cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=pagename)
 
-    return u'%d' % len(test)
+    if event_type == u'VIEWPAGE':
+        return u'%d' % sum(cache_views)
+    else:
+        return u'%d' % sum(cache_edits)
+