# HG changeset patch # User Marcin Kuzminski # Date 2019-10-19 11:31:19 # Node ID 5283766048b75e1dc7af267d2344c48687dcd4bd # Parent 94391e060d50eee7d820d9dcbc17eacdea5dcc15 admin: fixed problems with generating last change in admin panels. - from now on also updated_on will refer as last commit change instead of last update of DB. Reason for that is since we have audit logs the last db update should be taken from there along the change info. Storing last commit date in the dedicated field makes it searchable, sortable and faster to read. diff --git a/rhodecode/apps/admin/views/repo_groups.py b/rhodecode/apps/admin/views/repo_groups.py --- a/rhodecode/apps/admin/views/repo_groups.py +++ b/rhodecode/apps/admin/views/repo_groups.py @@ -19,6 +19,8 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import datetime import logging +import time + import formencode import formencode.htmlfill @@ -131,9 +133,10 @@ class AdminRepoGroupsView(BaseAppView, D def last_change(last_change): if isinstance(last_change, datetime.datetime) and not last_change.tzinfo: - delta = datetime.timedelta( - seconds=(datetime.datetime.now() - datetime.datetime.utcnow()).seconds) - last_change = last_change + delta + ts = time.time() + utc_offset = (datetime.datetime.fromtimestamp(ts) + - datetime.datetime.utcfromtimestamp(ts)).total_seconds() + last_change = last_change + datetime.timedelta(seconds=utc_offset) return _render("last_change", last_change) def desc(desc, personal): diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -2352,6 +2352,7 @@ class Repository(Base, BaseModel): cs_cache['updated_on'] = time.time() self.changeset_cache = cs_cache + self.updated_on = last_change Session().add(self) Session().commit() @@ -2858,6 +2859,7 @@ class RepoGroup(Base, BaseModel): for repo_group, repos in repo_groups_and_repos().items(): latest_repo_cs_cache = {} + _date_latest = empty_date for repo in repos: repo_cs_cache = repo.changeset_cache date_latest = latest_repo_cs_cache.get('date', empty_date) @@ -2866,9 +2868,11 @@ class RepoGroup(Base, BaseModel): if current_timestamp < datetime_to_time(parse_datetime(date_current)): latest_repo_cs_cache = repo_cs_cache latest_repo_cs_cache['source_repo_id'] = repo.repo_id + _date_latest = parse_datetime(latest_repo_cs_cache['date']) latest_repo_cs_cache['updated_on'] = time.time() repo_group.changeset_cache = latest_repo_cs_cache + repo_group.updated_on = _date_latest Session().add(repo_group) Session().commit() diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py --- a/rhodecode/model/repo.py +++ b/rhodecode/model/repo.py @@ -217,8 +217,11 @@ class RepoModel(BaseModel): def last_change(last_change): if admin and isinstance(last_change, datetime.datetime) and not last_change.tzinfo: - last_change = last_change + datetime.timedelta(seconds= - (datetime.datetime.now() - datetime.datetime.utcnow()).seconds) + ts = time.time() + utc_offset = (datetime.datetime.fromtimestamp(ts) + - datetime.datetime.utcfromtimestamp(ts)).total_seconds() + last_change = last_change + datetime.timedelta(seconds=utc_offset) + return _render("last_change", last_change) def rss_lnk(repo_name): @@ -381,7 +384,7 @@ class RepoModel(BaseModel): if ex_field: ex_field.field_value = kwargs[field] self.sa.add(ex_field) - cur_repo.updated_on = datetime.datetime.now() + self.sa.add(cur_repo) if source_repo_name != new_name: diff --git a/rhodecode/model/repo_group.py b/rhodecode/model/repo_group.py --- a/rhodecode/model/repo_group.py +++ b/rhodecode/model/repo_group.py @@ -28,6 +28,7 @@ import datetime import itertools import logging import shutil +import time import traceback import string @@ -519,7 +520,7 @@ class RepoGroupModel(BaseModel): if 'user' in form_data: repo_group.user = User.get_by_username(form_data['user']) - repo_group.updated_on = datetime.datetime.now() + self.sa.add(repo_group) # iterate over all members of this groups and do fixes @@ -536,7 +537,7 @@ class RepoGroupModel(BaseModel): log.debug('Fixing group %s to new name %s', obj.group_name, new_name) obj.group_name = new_name - obj.updated_on = datetime.datetime.now() + elif isinstance(obj, Repository): # we need to get all repositories from this new group and # rename them accordingly to new group path @@ -544,7 +545,7 @@ class RepoGroupModel(BaseModel): log.debug('Fixing repo %s to new name %s', obj.repo_name, new_name) obj.repo_name = new_name - obj.updated_on = datetime.datetime.now() + self.sa.add(obj) self._rename_group(old_path, new_path) @@ -714,8 +715,10 @@ class RepoGroupModel(BaseModel): def last_change(last_change): if admin and isinstance(last_change, datetime.datetime) and not last_change.tzinfo: - last_change = last_change + datetime.timedelta(seconds= - (datetime.datetime.now() - datetime.datetime.utcnow()).seconds) + ts = time.time() + utc_offset = (datetime.datetime.fromtimestamp(ts) + - datetime.datetime.utcfromtimestamp(ts)).total_seconds() + last_change = last_change + datetime.timedelta(seconds=utc_offset) return _render("last_change", last_change) def last_rev(repo_name, cs_cache):