Mercurial > kallithea
changeset 6220:7bffccee3a49
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.
author | Søren Løvborg <sorenl@unity3d.com> |
---|---|
date | Fri, 23 Sep 2016 14:05:42 +0200 |
parents | af3539a458f6 |
children | 7c0b55fb3a85 |
files | kallithea/controllers/admin/settings.py kallithea/controllers/api/api.py kallithea/lib/paster_commands/update_repoinfo.py kallithea/model/db.py kallithea/model/repo.py kallithea/tests/api/api_base.py kallithea/tests/fixture.py kallithea/tests/functional/test_admin_gists.py kallithea/tests/functional/test_home.py kallithea/tests/models/test_user_groups.py kallithea/tests/other/manual_test_vcs_operations.py |
diffstat | 11 files changed, 16 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/settings.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/controllers/admin/settings.py Fri Sep 23 14:05:42 2016 +0200 @@ -167,7 +167,7 @@ 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()
--- a/kallithea/controllers/api/api.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/controllers/api/api.py Fri Sep 23 14:05:42 2016 +0200 @@ -443,7 +443,7 @@ 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 @@ 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 @@ 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 @@ """ result = [] - for repo_group in RepoGroup.get_all(): + for repo_group in RepoGroup.query(): result.append(repo_group.get_api_data()) return result
--- a/kallithea/lib/paster_commands/update_repoinfo.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/lib/paster_commands/update_repoinfo.py Fri Sep 23 14:05:42 2016 +0200 @@ -54,7 +54,7 @@ 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(',')]
--- a/kallithea/model/db.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/model/db.py Fri Sep 23 14:05:42 2016 +0200 @@ -160,10 +160,6 @@ return res @classmethod - def get_all(cls): - return cls.query().all() - - @classmethod def delete(cls, id_): obj = cls.query().get(id_) Session().delete(obj)
--- a/kallithea/model/repo.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/model/repo.py Fri Sep 23 14:05:42 2016 +0200 @@ -179,7 +179,7 @@ @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()
--- a/kallithea/tests/api/api_base.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/api/api_base.py Fri Sep 23 14:05:42 2016 +0200 @@ -880,7 +880,7 @@ 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)
--- a/kallithea/tests/fixture.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/fixture.py Fri Sep 23 14:05:42 2016 +0200 @@ -252,7 +252,7 @@ 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)
--- a/kallithea/tests/functional/test_admin_gists.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/functional/test_admin_gists.py Fri Sep 23 14:05:42 2016 +0200 @@ -21,7 +21,7 @@ class TestGistsController(TestController): def teardown_method(self, method): - for g in Gist.get_all(): + for g in Gist.query(): GistModel().delete(g) Session().commit()
--- a/kallithea/tests/functional/test_home.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/functional/test_home.py Fri Sep 23 14:05:42 2016 +0200 @@ -17,7 +17,7 @@ #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')
--- a/kallithea/tests/models/test_user_groups.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/models/test_user_groups.py Fri Sep 23 14:05:42 2016 +0200 @@ -14,7 +14,7 @@ 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 @@ 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()
--- a/kallithea/tests/other/manual_test_vcs_operations.py Sat Sep 17 22:09:04 2016 +0200 +++ b/kallithea/tests/other/manual_test_vcs_operations.py Fri Sep 23 14:05:42 2016 +0200 @@ -272,7 +272,7 @@ 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 @@ 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 @@ 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()