[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Sep 28 12:13:48 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/eebbe6071741/
changeset:   eebbe6071741
branch:      feature-1268-speed-up-user-listing
user:        kindly
date:        2011-09-28 13:59:55
summary:     [merge] default
affected #:  119 files (-1 bytes)
Diff too large to display.
http://bitbucket.org/okfn/ckan/changeset/6de7960ca972/
changeset:   6de7960ca972
user:        kindly
date:        2011-09-28 14:13:23
summary:     [merge] feature-1268-user-speed listing improvemnet
affected #:  6 files (-1 bytes)

--- a/ckan/controllers/user.py	Wed Sep 28 11:45:57 2011 +0100
+++ b/ckan/controllers/user.py	Wed Sep 28 13:13:23 2011 +0100
@@ -61,7 +61,8 @@
         c.order_by = request.params.get('order_by', 'name')
 
         context = {'model': model,
-                   'user': c.user or c.author}
+                   'user': c.user or c.author,
+                   'return_query': True}
 
         data_dict = {'q':c.q,
                      'order_by':c.order_by}
@@ -75,7 +76,7 @@
         c.page = h.Page(
             collection=users_list,
             page=page,
-            item_count=len(users_list),
+            item_count=users_list.count(),
             items_per_page=LIMIT
             )
         return render('user/list.html')


--- a/ckan/logic/action/get.py	Wed Sep 28 11:45:57 2011 +0100
+++ b/ckan/logic/action/get.py	Wed Sep 28 13:13:23 2011 +0100
@@ -1,5 +1,5 @@
 from sqlalchemy.sql import select
-from sqlalchemy import or_, and_, func, desc
+from sqlalchemy import or_, and_, func, desc, case
 
 from ckan.logic import NotFound
 from ckan.logic import check_access
@@ -233,20 +233,46 @@
     q = data_dict.get('q','')
     order_by = data_dict.get('order_by','name')
 
-    query = model.Session.query(model.User, func.count(model.User.id))
+    query = model.Session.query(
+        model.User,
+        model.User.name.label('name'),
+        model.User.fullname.label('fullname'),
+        model.User.about.label('about'),
+        model.User.about.label('email'),
+        model.User.created.label('created'),
+        select([func.count(model.Revision.id)], or_(
+                model.Revision.author==model.User.name,
+                model.Revision.author==model.User.openid
+                )
+        ).label('number_of_edits'),
+        select([func.count(model.UserObjectRole.id)], and_(
+            model.UserObjectRole.user_id==model.User.id,
+            model.UserObjectRole.context=='Package',
+            model.UserObjectRole.role=='admin'
+            )
+        ).label('number_administered_packages')
+    )
+
     if q:
         query = model.User.search(q, query)
 
     if order_by == 'edits':
-        query = query.join((model.Revision, or_(
+        query = query.order_by(desc(
+            select([func.count(model.Revision.id)], or_(
                 model.Revision.author==model.User.name,
                 model.Revision.author==model.User.openid
-                )))
-        query = query.group_by(model.User)
-        query = query.order_by(desc(func.count(model.User.id)))
+                ))
+        ))
     else:
-        query = query.group_by(model.User)
-        query = query.order_by(model.User.name)
+        query = query.order_by(
+            case([(or_(model.User.fullname == None, model.User.fullname == ''),
+                   model.User.name)],
+                 else_=model.User.fullname)
+        )
+
+    ## hack for pagination
+    if context.get('return_query'):
+        return query
 
     users_list = []
 


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/migration/versions/042_user_revision_indexes.py	Wed Sep 28 13:13:23 2011 +0100
@@ -0,0 +1,13 @@
+from migrate import *
+
+def upgrade(migrate_engine):
+    migrate_engine.execute('''
+    BEGIN;
+    CREATE INDEX idx_revision_author ON "revision" (author);
+    CREATE INDEX idx_openid ON "user" (openid);
+    CREATE INDEX "idx_user_name_index" on "user"((CASE WHEN ("user".fullname IS NULL OR "user".fullname = '') THEN "user".name ELSE "user".fullname END));
+    COMMIT;
+    '''
+    )
+
+


--- a/ckan/model/user.py	Wed Sep 28 11:45:57 2011 +0100
+++ b/ckan/model/user.py	Wed Sep 28 13:13:23 2011 +0100
@@ -133,7 +133,6 @@
     def number_administered_packages(self):
         # have to import here to avoid circular imports
         import ckan.model as model
-        revisions_q = model.Session.query(model.Revision).filter_by(author=self.name)
         q = model.Session.query(model.PackageRole)
         q = q.filter_by(user=self, role=model.Role.ADMIN)
         return q.count()


--- a/ckan/templates/user/list.html	Wed Sep 28 11:45:57 2011 +0100
+++ b/ckan/templates/user/list.html	Wed Sep 28 13:13:23 2011 +0100
@@ -41,7 +41,7 @@
           ${h.linked_user(user['name'], maxlength=20)}
           </li><li class="created">
-            Member for ${h.time_ago_in_words_from_str(user['created'],granularity='month')}
+            Member for ${h.time_ago_in_words_from_str(user['created'].isoformat(),granularity='month')}
           </li><li><span class="edits" title="${user['number_of_edits']} Edits">

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list