[ckan-changes] commit/ckan: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Sep 15 11:52:12 UTC 2011
2 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/d800795fea81/
changeset: d800795fea81
branch: feature-1268-speed-up-user-listing
user: kindly
date: 2011-09-15 12:07:16
summary: [model user] make user listing fast and add indexes
affected #: 5 files (1.3 KB)
--- a/ckan/controllers/user.py Wed Sep 14 18:26:27 2011 +0100
+++ b/ckan/controllers/user.py Thu Sep 15 11:07:16 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 14 18:26:27 2011 +0100
+++ b/ckan/logic/action/get.py Thu Sep 15 11:07:16 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 Thu Sep 15 11:07:16 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 14 18:26:27 2011 +0100
+++ b/ckan/model/user.py Thu Sep 15 11:07:16 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 14 18:26:27 2011 +0100
+++ b/ckan/templates/user/list.html Thu Sep 15 11:07:16 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">
http://bitbucket.org/okfn/ckan/changeset/3ed4c719f251/
changeset: 3ed4c719f251
user: kindly
date: 2011-09-15 13:51:35
summary: [model] #1344 fix sqlite error
affected #: 1 file (227 bytes)
--- a/ckan/lib/create_test_data.py Thu Sep 15 12:21:47 2011 +0100
+++ b/ckan/lib/create_test_data.py Thu Sep 15 12:51:35 2011 +0100
@@ -138,7 +138,12 @@
elif attr == 'resources':
assert isinstance(val, (list, tuple))
for res_dict in val:
- non_extras = dict([(str(k), unicode(v)) for k, v in res_dict.items() if k != 'extras'])
+ non_extras = {}
+ for k, v in res_dict.items():
+ if k != 'extras':
+ if not isinstance(v, datetime.datetime):
+ v = unicode(v)
+ non_extras[str(k)] = v
extras = dict([(str(k), unicode(v)) for k, v in res_dict.get('extras', {}).items()])
pkg.add_resource(extras=extras, **non_extras)
elif attr == 'tags':
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