Skip to content

Commit

Permalink
test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Apr 26, 2018
1 parent fd1e423 commit 00fc5fd
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions kinto/core/storage/postgresql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,14 @@ def get_all(self, collection_id, parent_id, filters=None, sorting=None,
FROM records
WHERE {parent_id_filter}
AND collection_id = :collection_id
{conditions_deleted}
AND NOT deleted
{conditions_filter};
"""
select_query = """
SELECT id, as_epoch(last_modified) AS last_modified, data
SELECT {distinct} id, as_epoch(last_modified) AS last_modified, data
FROM records
WHERE {parent_id_filter}
WHERE {pagination_rules}
{parent_id_filter}
AND collection_id = :collection_id
{conditions_deleted}
{conditions_filter}
Expand Down Expand Up @@ -641,25 +642,30 @@ def get_all(self, collection_id, parent_id, filters=None, sorting=None,
if pagination_rules:
sql, holders = self._format_pagination(pagination_rules, id_field,
modified_field)
safeholders['pagination_rules'] = 'WHERE {}'.format(sql)
safeholders['pagination_rules'] = '{} AND'.format(sql)
placeholders.update(**holders)
else:
safeholders['pagination_rules'] = ''

print("PLACEHOLDERS", placeholders)
print("SAFEOLDERS", safeholders)

# Limit the number of results (pagination).
limit = min(self._max_fetch_size, limit) if limit else self._max_fetch_size
placeholders['pagination_limit'] = limit
print("LIMIT", limit)
print('self._max_fetch_size', self._max_fetch_size)

with self.client.connect(readonly=True) as conn:
result_count = conn.execute(count_query.format_map(safeholders), placeholders)
count_total, = result_count.fetchone()

if count_total == 0:
# If there are no records by that filtering, there's no point
# executing the select query.
return [], 0

result = conn.execute(select_query.format_map(safeholders), placeholders)
retrieved = result.fetchmany(self._max_fetch_size)

if len(retrieved) == 0:
return [], 0

records = []
for result in retrieved:
record = result['data']
Expand Down

0 comments on commit 00fc5fd

Please sign in to comment.