Show More
@@ -55,7 +55,7 b' from pyramid.threadlocal import get_curr' | |||
|
55 | 55 | from webhelpers2.text import remove_formatting |
|
56 | 56 | |
|
57 | 57 | from rhodecode.translation import _ |
|
58 | from rhodecode.lib.vcs import get_vcs_instance | |
|
58 | from rhodecode.lib.vcs import get_vcs_instance, VCSError | |
|
59 | 59 | from rhodecode.lib.vcs.backends.base import EmptyCommit, Reference |
|
60 | 60 | from rhodecode.lib.utils2 import ( |
|
61 | 61 | str2bool, safe_str, get_commit_safe, safe_unicode, sha1_safe, |
@@ -2359,7 +2359,8 b' class Repository(Base, BaseModel):' | |||
|
2359 | 2359 | |
|
2360 | 2360 | def update_commit_cache(self, cs_cache=None, config=None): |
|
2361 | 2361 | """ |
|
2362 |
Update cache of last commit for repository |
|
|
2362 | Update cache of last commit for repository | |
|
2363 | cache_keys should be:: | |
|
2363 | 2364 | |
|
2364 | 2365 | source_repo_id |
|
2365 | 2366 | short_id |
@@ -2373,11 +2374,17 b' class Repository(Base, BaseModel):' | |||
|
2373 | 2374 | |
|
2374 | 2375 | """ |
|
2375 | 2376 | from rhodecode.lib.vcs.backends.base import BaseChangeset |
|
2377 | from rhodecode.lib.vcs.utils.helpers import parse_datetime | |
|
2378 | empty_date = datetime.datetime.fromtimestamp(0) | |
|
2379 | ||
|
2376 | 2380 | if cs_cache is None: |
|
2377 | 2381 | # use no-cache version here |
|
2378 | scm_repo = self.scm_instance(cache=False, config=config) | |
|
2379 | ||
|
2382 | try: | |
|
2383 | scm_repo = self.scm_instance(cache=False, config=config) | |
|
2384 | except VCSError: | |
|
2385 | scm_repo = None | |
|
2380 | 2386 | empty = scm_repo is None or scm_repo.is_empty() |
|
2387 | ||
|
2381 | 2388 | if not empty: |
|
2382 | 2389 | cs_cache = scm_repo.get_commit( |
|
2383 | 2390 | pre_load=["author", "date", "message", "parents", "branch"]) |
@@ -2395,33 +2402,39 b' class Repository(Base, BaseModel):' | |||
|
2395 | 2402 | |
|
2396 | 2403 | # check if we have maybe already latest cached revision |
|
2397 | 2404 | if is_outdated(cs_cache) or not self.changeset_cache: |
|
2398 |
_de |
|
|
2399 |
last_change = cs_cache.get('date') or _de |
|
|
2405 | _current_datetime = datetime.datetime.utcnow() | |
|
2406 | last_change = cs_cache.get('date') or _current_datetime | |
|
2400 | 2407 | # we check if last update is newer than the new value |
|
2401 | 2408 | # if yes, we use the current timestamp instead. Imagine you get |
|
2402 | 2409 | # old commit pushed 1y ago, we'd set last update 1y to ago. |
|
2403 | 2410 | last_change_timestamp = datetime_to_time(last_change) |
|
2404 | 2411 | current_timestamp = datetime_to_time(last_change) |
|
2405 | if last_change_timestamp > current_timestamp: | |
|
2406 |
cs_cache['date'] = _de |
|
|
2407 | ||
|
2412 | if last_change_timestamp > current_timestamp and not empty: | |
|
2413 | cs_cache['date'] = _current_datetime | |
|
2414 | ||
|
2415 | _date_latest = parse_datetime(cs_cache.get('date') or empty_date) | |
|
2408 | 2416 | cs_cache['updated_on'] = time.time() |
|
2409 | 2417 | self.changeset_cache = cs_cache |
|
2410 | 2418 | self.updated_on = last_change |
|
2411 | 2419 | Session().add(self) |
|
2412 | 2420 | Session().commit() |
|
2413 | 2421 | |
|
2414 | log.debug('updated repo `%s` with new commit cache %s', | |
|
2415 | self.repo_name, cs_cache) | |
|
2416 | 2422 | else: |
|
2417 | cs_cache = self.changeset_cache | |
|
2423 | if empty: | |
|
2424 | cs_cache = EmptyCommit().__json__() | |
|
2425 | else: | |
|
2426 | cs_cache = self.changeset_cache | |
|
2427 | ||
|
2428 | _date_latest = parse_datetime(cs_cache.get('date') or empty_date) | |
|
2429 | ||
|
2418 | 2430 | cs_cache['updated_on'] = time.time() |
|
2419 | 2431 | self.changeset_cache = cs_cache |
|
2432 | self.updated_on = _date_latest | |
|
2420 | 2433 | Session().add(self) |
|
2421 | 2434 | Session().commit() |
|
2422 | 2435 | |
|
2423 | log.debug('Skipping update_commit_cache for repo:`%s` ' | |
|
2424 | 'commit already with latest changes', self.repo_name) | |
|
2436 | log.debug('updated repo `%s` with new commit cache %s, and last update_date: %s', | |
|
2437 | self.repo_name, cs_cache, _date_latest) | |
|
2425 | 2438 | |
|
2426 | 2439 | @property |
|
2427 | 2440 | def tip(self): |
@@ -2886,7 +2899,8 b' class RepoGroup(Base, BaseModel):' | |||
|
2886 | 2899 | |
|
2887 | 2900 | def update_commit_cache(self, config=None): |
|
2888 | 2901 | """ |
|
2889 |
Update cache of last c |
|
|
2902 | Update cache of last commit for newest repository inside this repository group. | |
|
2903 | cache_keys should be:: | |
|
2890 | 2904 | |
|
2891 | 2905 | source_repo_id |
|
2892 | 2906 | short_id |
@@ -2899,50 +2913,37 b' class RepoGroup(Base, BaseModel):' | |||
|
2899 | 2913 | |
|
2900 | 2914 | """ |
|
2901 | 2915 | from rhodecode.lib.vcs.utils.helpers import parse_datetime |
|
2902 | ||
|
2903 | def repo_groups_and_repos(): | |
|
2904 | all_entries = OrderedDefaultDict(list) | |
|
2905 | ||
|
2906 | def _get_members(root_gr, pos=0): | |
|
2907 | ||
|
2908 | for repo in root_gr.repositories: | |
|
2909 | all_entries[root_gr].append(repo) | |
|
2910 | ||
|
2911 | # fill in all parent positions | |
|
2912 | for parent_group in root_gr.parents: | |
|
2913 | all_entries[parent_group].extend(all_entries[root_gr]) | |
|
2914 | ||
|
2915 | children_groups = root_gr.children.all() | |
|
2916 | if children_groups: | |
|
2917 | for cnt, gr in enumerate(children_groups, 1): | |
|
2918 | _get_members(gr, pos=pos+cnt) | |
|
2919 | ||
|
2920 | _get_members(root_gr=self) | |
|
2921 | return all_entries | |
|
2922 | ||
|
2923 | 2916 | empty_date = datetime.datetime.fromtimestamp(0) |
|
2924 | for repo_group, repos in repo_groups_and_repos().items(): | |
|
2925 | ||
|
2926 | latest_repo_cs_cache = {} | |
|
2927 | _date_latest = empty_date | |
|
2928 |
for |
|
|
2929 | repo_cs_cache = repo.changeset_cache | |
|
2930 | date_latest = latest_repo_cs_cache.get('date', empty_date) | |
|
2931 | date_current = repo_cs_cache.get('date', empty_date) | |
|
2932 | current_timestamp = datetime_to_time(parse_datetime(date_latest)) | |
|
2933 | if current_timestamp < datetime_to_time(parse_datetime(date_current)): | |
|
2934 |
|
|
|
2935 | latest_repo_cs_cache['source_repo_id'] = repo.repo_id | |
|
2936 | _date_latest = parse_datetime(latest_repo_cs_cache['date']) | |
|
2937 | ||
|
2938 |
latest_repo_cs_cache |
|
|
2939 | repo_group.changeset_cache = latest_repo_cs_cache | |
|
2940 | repo_group.updated_on = _date_latest | |
|
2941 | Session().add(repo_group) | |
|
2942 | Session().commit() | |
|
2943 | ||
|
2944 | log.debug('updated repo group `%s` with new commit cache %s', | |
|
2945 | repo_group.group_name, latest_repo_cs_cache) | |
|
2917 | ||
|
2918 | def repo_groups_and_repos(root_gr): | |
|
2919 | for _repo in root_gr.repositories: | |
|
2920 | yield _repo | |
|
2921 | for child_group in root_gr.children.all(): | |
|
2922 | yield child_group | |
|
2923 | ||
|
2924 | latest_repo_cs_cache = {} | |
|
2925 | for obj in repo_groups_and_repos(self): | |
|
2926 | repo_cs_cache = obj.changeset_cache | |
|
2927 | date_latest = latest_repo_cs_cache.get('date', empty_date) | |
|
2928 | date_current = repo_cs_cache.get('date', empty_date) | |
|
2929 | current_timestamp = datetime_to_time(parse_datetime(date_latest)) | |
|
2930 | if current_timestamp < datetime_to_time(parse_datetime(date_current)): | |
|
2931 | latest_repo_cs_cache = repo_cs_cache | |
|
2932 | if hasattr(obj, 'repo_id'): | |
|
2933 | latest_repo_cs_cache['source_repo_id'] = obj.repo_id | |
|
2934 | else: | |
|
2935 | latest_repo_cs_cache['source_repo_id'] = repo_cs_cache.get('source_repo_id') | |
|
2936 | ||
|
2937 | _date_latest = parse_datetime(latest_repo_cs_cache.get('date') or empty_date) | |
|
2938 | ||
|
2939 | latest_repo_cs_cache['updated_on'] = time.time() | |
|
2940 | self.changeset_cache = latest_repo_cs_cache | |
|
2941 | self.updated_on = _date_latest | |
|
2942 | Session().add(self) | |
|
2943 | Session().commit() | |
|
2944 | ||
|
2945 | log.debug('updated repo group `%s` with new commit cache %s, and last update_date: %s', | |
|
2946 | self.group_name, latest_repo_cs_cache, _date_latest) | |
|
2946 | 2947 | |
|
2947 | 2948 | def permissions(self, with_admins=True, with_owner=True, |
|
2948 | 2949 | expand_from_user_groups=False): |
General Comments 0
You need to be logged in to leave comments.
Login now