Mercurial > kallithea
comparison rhodecode/model/db.py @ 1744:d41a115d9a39 beta
remove cache from default perms. In some cases of concurrent repo removal it crashed.
There's no speed regression on this one.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 01 Dec 2011 00:40:28 +0200 |
parents | ac54aa4200e8 |
children | 8804715404c9 |
comparison
equal
deleted
inserted
replaced
1743:db4852ed3413 | 1744:d41a115d9a39 |
---|---|
678 def scm_instance_cached(self): | 678 def scm_instance_cached(self): |
679 @cache_region('long_term') | 679 @cache_region('long_term') |
680 def _c(repo_name): | 680 def _c(repo_name): |
681 return self.__get_instance() | 681 return self.__get_instance() |
682 rn = self.repo_name | 682 rn = self.repo_name |
683 | 683 log.debug('Getting cached instance of repo') |
684 inv = self.invalidate | 684 inv = self.invalidate |
685 if inv is not None: | 685 if inv is not None: |
686 region_invalidate(_c, None, rn) | 686 region_invalidate(_c, None, rn) |
687 # update our cache | 687 # update our cache |
688 CacheInvalidation.set_valid(inv.cache_key) | 688 CacheInvalidation.set_valid(inv.cache_key) |
689 return _c(rn) | 689 return _c(rn) |
690 | 690 |
691 def __get_instance(self): | 691 def __get_instance(self): |
692 | |
693 repo_full_path = self.repo_full_path | 692 repo_full_path = self.repo_full_path |
694 | |
695 try: | 693 try: |
696 alias = get_scm(repo_full_path)[0] | 694 alias = get_scm(repo_full_path)[0] |
697 log.debug('Creating instance of %s repository', alias) | 695 log.debug('Creating instance of %s repository', alias) |
698 backend = get_backend(alias) | 696 backend = get_backend(alias) |
699 except VCSError: | 697 except VCSError: |
702 'filesystem run rescan repositories with ' | 700 'filesystem run rescan repositories with ' |
703 '"destroy old data " option from admin panel') | 701 '"destroy old data " option from admin panel') |
704 return | 702 return |
705 | 703 |
706 if alias == 'hg': | 704 if alias == 'hg': |
707 | |
708 repo = backend(safe_str(repo_full_path), create=False, | 705 repo = backend(safe_str(repo_full_path), create=False, |
709 baseui=self._ui) | 706 baseui=self._ui) |
710 # skip hidden web repository | 707 # skip hidden web repository |
711 if repo._get_hidden(): | 708 if repo._get_hidden(): |
712 return | 709 return |
851 @classmethod | 848 @classmethod |
852 def get_by_key(cls, key): | 849 def get_by_key(cls, key): |
853 return cls.query().filter(cls.permission_name == key).scalar() | 850 return cls.query().filter(cls.permission_name == key).scalar() |
854 | 851 |
855 @classmethod | 852 @classmethod |
856 def get_default_perms(cls, default_user_id, cache=True): | 853 def get_default_perms(cls, default_user_id): |
857 q = Session().query(UserRepoToPerm, Repository, cls)\ | 854 q = Session().query(UserRepoToPerm, Repository, cls)\ |
858 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ | 855 .join((Repository, UserRepoToPerm.repository_id == Repository.repo_id))\ |
859 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ | 856 .join((cls, UserRepoToPerm.permission_id == cls.permission_id))\ |
860 .filter(UserRepoToPerm.user_id == default_user_id) | 857 .filter(UserRepoToPerm.user_id == default_user_id) |
861 if cache: | |
862 q = q.options(FromCache("sql_cache_short", "get_default_perms")) | |
863 | 858 |
864 return q.all() | 859 return q.all() |
865 | 860 |
866 | 861 |
867 class UserRepoToPerm(Base, BaseModel): | 862 class UserRepoToPerm(Base, BaseModel): |