changeset 6226:590d5b7a2b26

db: do case-insensitive explicit sorting of RepoGroup names This does not change the implicit sorting enabled via __mapper_args__, which is a bad idea anyway (and now deprecated), and will have to be dealt with in a later changeset. The use of __mapper_args__ implicitly adds sorting to every query of RepoGroup objects throughout the code (including implicit queries via relationships). For the relationships, __mapper_args can be replaced with "order_by" on each individual relationship, and it's reasonably straight-forward to identify every RepoGroup query throughout the code, and add explicit sorting. But we don't really need that sorting most of the time, so a better way forward may be to identify all the places that actually needs the sorting, make it explicit there, and then kill the __mapper_args__. (Anyway, future work.)
author Søren Løvborg <sorenl@unity3d.com>
date Thu, 15 Sep 2016 15:13:27 +0200
parents 0b7b8e8031e6
children 555c8d26988f
files kallithea/controllers/admin/repo_groups.py kallithea/controllers/home.py kallithea/model/db.py
diffstat 3 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py	Wed Sep 14 15:53:13 2016 +0200
+++ b/kallithea/controllers/admin/repo_groups.py	Thu Sep 15 15:13:27 2016 +0200
@@ -303,8 +303,7 @@
         #overwrite our cached list with current filter
         c.repo_cnt = 0
 
-        groups = RepoGroup.query().order_by(RepoGroup.group_name) \
-            .filter(RepoGroup.group_parent_id == c.group.group_id).all()
+        groups = RepoGroup.query(sorted=True).filter_by(parent_group=c.group).all()
         c.groups = self.scm_model.get_repo_groups(groups)
 
         c.repos_list = Repository.query(sorted=True).filter_by(group=c.group).all()
--- a/kallithea/controllers/home.py	Wed Sep 14 15:53:13 2016 +0200
+++ b/kallithea/controllers/home.py	Thu Sep 15 15:13:27 2016 +0200
@@ -74,7 +74,7 @@
             log.debug('generating switcher repo/groups list')
             all_repos = Repository.query(sorted=True).all()
             repo_iter = self.scm_model.get_repos(all_repos)
-            all_groups = RepoGroup.query().order_by(RepoGroup.group_name).all()
+            all_groups = RepoGroup.query(sorted=True).all()
             repo_groups_iter = self.scm_model.get_repo_groups(all_groups)
 
             res = [{
--- a/kallithea/model/db.py	Wed Sep 14 15:53:13 2016 +0200
+++ b/kallithea/model/db.py	Thu Sep 15 15:13:27 2016 +0200
@@ -1518,7 +1518,7 @@
         CheckConstraint('group_id != group_parent_id', name='ck_groups_no_self_parent'),
         _table_args_default_dict,
     )
-    __mapper_args__ = {'order_by': 'group_name'}
+    __mapper_args__ = {'order_by': 'group_name'} # TODO: Deprecated as of SQLAlchemy 1.1.
 
     SEP = ' &raquo; '