changeset 1887:3246fcce2402

backported fixes for statistics from beta branch, try to fix issue #271 - version bump
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 12 Jan 2012 06:21:48 +0200
parents ea011e05fb0a
children 6b25e6819753
files rhodecode/__init__.py rhodecode/controllers/summary.py rhodecode/lib/celerylib/tasks.py rhodecode/tests/functional/test_summary.py setup.py
diffstat 5 files changed, 29 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/__init__.py	Sat Jan 07 01:42:18 2012 +0200
+++ b/rhodecode/__init__.py	Thu Jan 12 06:21:48 2012 +0200
@@ -25,9 +25,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 import platform
 
-VERSION = (1, 2, 3)
+VERSION = (1, 2, 4)
 __version__ = '.'.join((str(each) for each in VERSION[:4]))
-__dbversion__ = 3 #defines current db version for migrations
+__dbversion__ = 3  # defines current db version for migrations
 __platform__ = platform.system()
 __license__ = 'GPLv3'
 
--- a/rhodecode/controllers/summary.py	Sat Jan 07 01:42:18 2012 +0200
+++ b/rhodecode/controllers/summary.py	Thu Jan 12 06:21:48 2012 +0200
@@ -115,9 +115,11 @@
         ts_max_y = mktime(td.timetuple())
 
         if dbrepo.enable_statistics:
+            c.show_stats = True
             c.no_data_msg = _('No data loaded yet')
             run_task(get_commits_stats, c.dbrepo.repo_name, ts_min_y, ts_max_y)
         else:
+            c.show_stats = False
             c.no_data_msg = _('Statistics are disabled for this repository')
         c.ts_min = ts_min_m
         c.ts_max = ts_max_y
@@ -143,8 +145,8 @@
                                             key=lambda k: k[1])[:10]
                                         )
                                     )
-            last_rev = stats.stat_on_revision
-            c.repo_last_rev = c.rhodecode_repo.count() - 1 \
+            last_rev = stats.stat_on_revision + 1
+            c.repo_last_rev = c.rhodecode_repo.count()\
                 if c.rhodecode_repo.revisions else 0
             if last_rev == 0 or c.repo_last_rev == 0:
                 pass
--- a/rhodecode/lib/celerylib/tasks.py	Sat Jan 07 01:42:18 2012 +0200
+++ b/rhodecode/lib/celerylib/tasks.py	Thu Jan 12 06:21:48 2012 +0200
@@ -100,6 +100,7 @@
 
     log.info('running task with lockkey %s', lockkey)
     try:
+        sa = get_session()
         lock = l = DaemonLock(file_=jn(lockkey_path, lockkey))
 
         # for js data compatibilty cleans the key for person from '
@@ -109,20 +110,18 @@
         commits_by_day_aggregate = {}
         repos_path = get_repos_path()
         repo = get_repo(safe_str(os.path.join(repos_path, repo_name)))
-        repo_size = len(repo.revisions)
-        #return if repo have no revisions
+        repo_size = repo.count()
+        # return if repo have no revisions
         if repo_size < 1:
             lock.release()
             return True
 
         skip_date_limit = True
         parse_limit = int(config['app_conf'].get('commit_parse_limit'))
-        last_rev = 0
+        last_rev = None
         last_cs = None
         timegetter = itemgetter('time')
 
-        sa = get_session()
-
         dbrepo = sa.query(Repository)\
             .filter(Repository.repo_name == repo_name).scalar()
         cur_stats = sa.query(Statistics)\
@@ -132,9 +131,9 @@
             last_rev = cur_stats.stat_on_revision
 
         if last_rev == repo.get_changeset().revision and repo_size > 1:
-            #pass silently without any work if we're not on first revision or
-            #current state of parsing revision(from db marker) is the
-            #last revision
+            # pass silently without any work if we're not on first revision or
+            # current state of parsing revision(from db marker) is the
+            # last revision
             lock.release()
             return True
 
@@ -146,8 +145,10 @@
         log.debug('starting parsing %s', parse_limit)
         lmktime = mktime
 
-        last_rev = last_rev + 1 if last_rev > 0 else last_rev
-
+        last_rev = last_rev + 1 if last_rev >= 0 else 0
+        log.debug('Getting revisions from %s to %s' % (
+             last_rev, last_rev + parse_limit)
+        )
         for cs in repo[last_rev:last_rev + parse_limit]:
             last_cs = cs  # remember last parsed changeset
             k = lmktime([cs.date.timetuple()[0], cs.date.timetuple()[1],
--- a/rhodecode/tests/functional/test_summary.py	Sat Jan 07 01:42:18 2012 +0200
+++ b/rhodecode/tests/functional/test_summary.py	Thu Jan 12 06:21:48 2012 +0200
@@ -2,6 +2,7 @@
 from rhodecode.model.db import Repository
 from rhodecode.lib.utils import invalidate_cache
 
+
 class TestSummaryController(TestController):
 
     def test_index(self):
@@ -22,23 +23,22 @@
         #codes stats
         self._enable_stats()
 
-
         invalidate_cache('get_repo_cached_%s' % HG_REPO)
         response = self.app.get(url(controller='summary', action='index',
                                     repo_name=HG_REPO))
 
-        self.assertTrue("""var data = {"py": {"count": 42, "desc": """
-                        """["Python"]}, "rst": {"count": 11, "desc": """
-                        """["Rst"]}, "sh": {"count": 2, "desc": ["Bash"]}, """
-                        """"makefile": {"count": 1, "desc": ["Makefile", """
-                        """"Makefile"]}, "cfg": {"count": 1, "desc": ["Ini"]},"""
-                        """ "css": {"count": 1, "desc": ["Css"]}, "bat": """
-                        """{"count": 1, "desc": ["Batch"]}};"""
-                        in response.body)
+        response.mustcontain(
+            """var data = {"py": {"count": 42, "desc": """
+            """["Python"]}, "rst": {"count": 11, "desc": """
+            """["Rst"]}, "sh": {"count": 2, "desc": ["Bash"]}, """
+            """"makefile": {"count": 1, "desc": ["Makefile", """
+            """"Makefile"]}, "cfg": {"count": 1, "desc": ["Ini"]},"""
+            """ "css": {"count": 1, "desc": ["Css"]}, "bat": """
+            """{"count": 1, "desc": ["Batch"]}};"""
+        )
 
         # clone url...
-        self.assertTrue("""<input type="text" id="clone_url" readonly="readonly" value="hg clone http://test_admin@localhost:80/%s" size="70"/>""" % HG_REPO in response.body)
-
+        response.mustcontain("""<input type="text" id="clone_url" readonly="readonly" value="hg clone http://test_admin@localhost:80/%s" size="70"/>""" % HG_REPO)
 
     def _enable_stats(self):
         r = Repository.get_by_repo_name(HG_REPO)
--- a/setup.py	Sat Jan 07 01:42:18 2012 +0200
+++ b/setup.py	Thu Jan 12 06:21:48 2012 +0200
@@ -23,7 +23,7 @@
         "babel",
         "python-dateutil>=1.5.0,<2.0.0",
         "dulwich>=0.8.0,<0.9.0",
-        "vcs==0.2.3",
+        "vcs==0.2.2",
         "webob==1.0.8"
     ]