Changeset - 7bffccee3a49
[Not reviewed]
default
0 11 0
Søren Løvborg - 9 years ago 2016-09-23 14:05:42
sorenl@unity3d.com
db: inline calls to get_all

This method saves basically no typing, compared to "query().all()".
Additionally, "all()" returns a list, forcing all records to be loaded
into a memory at the same time, but some callers just need to iterate
over the objects one at a time, in which case "query()" alone is more
efficient. In one case, the caller can even use "count()" and avoid
loading any objects from the database at all.
11 files changed with 16 insertions and 20 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -167,7 +167,7 @@ class SettingsController(BaseController)
 

	
 
            if invalidate_cache:
 
                log.debug('invalidating all repositories cache')
 
                for repo in Repository.get_all():
 
                for repo in Repository.query():
 
                    ScmModel().mark_for_invalidation(repo.repo_name)
 

	
 
            filesystem_repos = ScmModel().repo_scan()
kallithea/controllers/api/api.py
Show inline comments
 
@@ -443,7 +443,7 @@ class ApiController(JSONRPCController):
 
            user = get_user_or_error(userid)
 

	
 
        # show all locks
 
        for r in Repository.get_all():
 
        for r in Repository.query():
 
            userid, time_ = r.locked
 
            if time_:
 
                _api_data = r.get_api_data()
 
@@ -848,7 +848,7 @@ class ApiController(JSONRPCController):
 

	
 
        result = []
 
        _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',)
 
        for user_group in UserGroupList(UserGroup.get_all(),
 
        for user_group in UserGroupList(UserGroup.query().all(),
 
                                        perm_set=_perms):
 
            result.append(user_group.get_api_data())
 
        return result
 
@@ -1272,7 +1272,7 @@ class ApiController(JSONRPCController):
 
        if not HasPermissionAny('hg.admin')():
 
            repos = RepoModel().get_all_user_repos(user=self.authuser.user_id)
 
        else:
 
            repos = Repository.get_all()
 
            repos = Repository.query()
 

	
 
        for repo in repos:
 
            result.append(repo.get_api_data())
 
@@ -1950,7 +1950,7 @@ class ApiController(JSONRPCController):
 

	
 
        """
 
        result = []
 
        for repo_group in RepoGroup.get_all():
 
        for repo_group in RepoGroup.query():
 
            result.append(repo_group.get_api_data())
 
        return result
 

	
kallithea/lib/paster_commands/update_repoinfo.py
Show inline comments
 
@@ -54,7 +54,7 @@ class Command(BasePasterCommand):
 

	
 

	
 
        if self.options.repo_update_list is None:
 
            repo_list = Repository.get_all()
 
            repo_list = Repository.query().all()
 
        else:
 
            repo_names = [safe_unicode(n.strip())
 
                          for n in self.options.repo_update_list.split(',')]
kallithea/model/db.py
Show inline comments
 
@@ -160,10 +160,6 @@ class BaseModel(object):
 
        return res
 

	
 
    @classmethod
 
    def get_all(cls):
 
        return cls.query().all()
 

	
 
    @classmethod
 
    def delete(cls, id_):
 
        obj = cls.query().get(id_)
 
        Session().delete(obj)
kallithea/model/repo.py
Show inline comments
 
@@ -179,7 +179,7 @@ class RepoModel(BaseModel):
 
    @classmethod
 
    def update_repoinfo(cls, repositories=None):
 
        if repositories is None:
 
            repositories = Repository.get_all()
 
            repositories = Repository.query()
 
        for repo in repositories:
 
            repo.update_changeset_cache()
 

	
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -880,7 +880,7 @@ class _BaseTestApi(object):
 
        response = api_call(self, params)
 

	
 
        result = []
 
        for repo in Repository.get_all():
 
        for repo in Repository.query():
 
            result.append(repo.get_api_data())
 
        ret = jsonify(result)
 

	
kallithea/tests/fixture.py
Show inline comments
 
@@ -252,7 +252,7 @@ class Fixture(object):
 
        return gist
 

	
 
    def destroy_gists(self, gistid=None):
 
        for g in Gist.get_all():
 
        for g in Gist.query():
 
            if gistid:
 
                if gistid == g.gist_access_id:
 
                    GistModel().delete(g)
kallithea/tests/functional/test_admin_gists.py
Show inline comments
 
@@ -21,7 +21,7 @@ def _create_gist(f_name, content='some g
 
class TestGistsController(TestController):
 

	
 
    def teardown_method(self, method):
 
        for g in Gist.get_all():
 
        for g in Gist.query():
 
            GistModel().delete(g)
 
        Session().commit()
 

	
kallithea/tests/functional/test_home.py
Show inline comments
 
@@ -17,7 +17,7 @@ class TestHomeController(TestController)
 
        #if global permission is set
 
        response.mustcontain('Add Repository')
 
        # html in javascript variable:
 
        response.mustcontain('var data = {"totalRecords": %s' % len(Repository.get_all()))
 
        response.mustcontain('var data = {"totalRecords": %s' % Repository.query().count())
 
        response.mustcontain(r'href=\"/%s\"' % HG_REPO)
 

	
 
        response.mustcontain(r'<span class="repotag">git')
kallithea/tests/models/test_user_groups.py
Show inline comments
 
@@ -14,7 +14,7 @@ class TestUserGroups(TestController):
 

	
 
    def teardown_method(self, method):
 
        # delete all groups
 
        for gr in UserGroup.get_all():
 
        for gr in UserGroup.query():
 
            fixture.destroy_user_group(gr)
 
        Session().commit()
 

	
 
@@ -30,7 +30,7 @@ class TestUserGroups(TestController):
 
    def test_enforce_groups(self, pre_existing, regular_should_be,
 
                            external_should_be, groups, expected):
 
        # delete all groups
 
        for gr in UserGroup.get_all():
 
        for gr in UserGroup.query():
 
            fixture.destroy_user_group(gr)
 
        Session().commit()
 

	
kallithea/tests/other/manual_test_vcs_operations.py
Show inline comments
 
@@ -272,7 +272,7 @@ class TestVCSOperations(TestController):
 
        fixture.create_fork(GIT_REPO, fork_name)
 
        clone_url = _construct_url(fork_name).split()[0]
 
        stdout, stderr = _add_files_and_push('git', DEST, clone_url=clone_url)
 
        print [(x.repo_full_path,x.repo_path) for x in Repository.get_all()] # TODO: what is this for
 
        print [(x.repo_full_path,x.repo_path) for x in Repository.query()] # TODO: what is this for
 
        _check_proper_git_push(stdout, stderr)
 

	
 
    def test_push_invalidates_cache_hg(self):
 
@@ -527,7 +527,7 @@ class TestVCSOperations(TestController):
 
            assert 'abort: HTTP Error 403: Forbidden' in stderr
 
        finally:
 
            #release IP restrictions
 
            for ip in UserIpMap.get_all():
 
            for ip in UserIpMap.query():
 
                UserIpMap.delete(ip.ip_id)
 
            Session().commit()
 

	
 
@@ -555,7 +555,7 @@ class TestVCSOperations(TestController):
 
            assert re.search(r'\b403\b', stderr)
 
        finally:
 
            #release IP restrictions
 
            for ip in UserIpMap.get_all():
 
            for ip in UserIpMap.query():
 
                UserIpMap.delete(ip.ip_id)
 
            Session().commit()
 

	
0 comments (0 inline, 0 general)