Skip to content

Commit 9f3e937

Browse files
authored
Merge pull request #170 from karlproject/use-karlex.community_zoid
Changed queries that use community id to use the new
2 parents 66a1529 + b029332 commit 9f3e937

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
karl package Changelog
22
======================
33

4+
- Changed queries that use community id to use the new
5+
karlex.community_id column because it's updated more reliably.
6+
47
4.38.0 (2017-07-13)
58
===================
69

karl/box/apiviews.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ def token(self):
116116
(state->>'content_modified')::timestamp::text as last_activity,
117117
get_path(state) as path,
118118
(select count(*)
119-
from newt sn
120-
where get_community_zoid(sn.zoid, sn.class_name, sn.state) =
121-
newt.zoid
119+
from newt sn natural join karlex
120+
where karlex.community_zoid = newt.zoid
122121
and
123122
interfaces(sn.class_name) &&
124123
array[

karl/content/views/blog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ def show_blog_view(context, request):
9393
from newt.db import search
9494
community = find_community(context)
9595
community_cond = qbe.sql(context._p_jar, dict(community=community))
96-
results = search.where(
96+
results = search.search(
9797
context._p_jar,
9898
"""
99+
select * from newt natural join karlex where
99100
class_name = 'karl.content.models.blog.BlogEntry'
100101
and """ + community_cond + """
101102
and newt_can_view(state, %s)
@@ -581,7 +582,7 @@ def archive_portlet(context, request):
581582
"""
582583
select month, count(*) from (
583584
select substring(state->>'created' from 1 for 7) as month
584-
from newt
585+
from newt natural join karlex
585586
where class_name = 'karl.content.models.blog.BlogEntry'
586587
and """ + community_cond + """
587588
and newt_can_view(state, %s)

karl/models/newtqbe.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def iface_names(ifaces):
6262
$$ language plpgsql immutable;
6363
"""
6464
from ZODB.utils import u64
65-
qbe['community'] = scalar("get_community_zoid(zoid, class_name, state)",
65+
qbe['community'] = scalar("karlex.community_zoid",
6666
convert = lambda c: u64(c._p_oid))
6767
#
6868
#############################################################################
@@ -189,24 +189,18 @@ def __init__(self, context, request=None):
189189
def __call__(self, sort_index=None, reverse=False,
190190
offset=None, limit=None, want_count=True,
191191
**kw):
192-
if sort_index is not None:
193-
order_by = [(sort_index, reverse)]
194-
else:
195-
order_by = ()
192+
sql = self.sql(sort_index, reverse, offset, limit, want_count, **kw)
196193

197194
conn = self.context._p_jar
198-
sql = qbe.sql(conn, dequerify(kw), order_by=order_by)
199-
sql = "state ? '__parent__' AND state ? '__name__' AND \n" + sql
200-
201195
if limit is not None:
202196
if want_count:
203-
count, obs = newt.db.search.where_batch(
197+
count, obs = newt.db.search.search_batch(
204198
conn, sql, offset or 0, limit)
205199
return count, obs, ob_resolver
206200

207201
sql += ' limit %d' % limit
208202

209-
obs = newt.db.search.where(conn, sql)
203+
obs = newt.db.search.search(conn, sql)
210204
return len(obs), obs, ob_resolver
211205

212206
def sql(self, sort_index=None, reverse=False,
@@ -218,9 +212,16 @@ def sql(self, sort_index=None, reverse=False,
218212
order_by = ()
219213

220214
sql = qbe.sql(self.context._p_jar, dequerify(kw), order_by=order_by)
221-
sql = "state ? '__parent__' AND state ? '__name__' AND \n" + sql
215+
if 'community' not in kw:
216+
sql = "state ? '__parent__' AND state ? '__name__' AND \n" + sql
222217

223-
if limit is not None:
218+
if 'karlex.' in sql:
219+
sql = 'select * from newt natural join karlex\nwhere ' + sql
220+
else:
221+
sql = 'select * from newt\nwhere ' + sql
222+
223+
224+
if limit is not None and not want_count:
224225
sql += ' limit %d' % limit
225226

226227
return sql

0 commit comments

Comments
 (0)