comparison src/pgsql_storage.py @ 374:40e5edd7ea11

storage: changed items order: items were so far ordered by item_id, i.e. by order of creation. This has been changed to order them by date of last update, so an item overwritting an old one appears on top (with former behaviour, it was staying at the same place). The XEP is not clear on that, but this seems more in correct with ยง 6.5.7 which says "implementations SHOULD return the N most recent (as opposed to the N oldest) items".
author Goffi <goffi@goffi.org>
date Thu, 03 Jan 2019 20:31:03 +0100
parents dabee42494ac
children 9a787881b824
comparison
equal deleted inserted replaced
373:26e46a3043e5 374:40e5edd7ea11
435 NATURAL JOIN nodes 435 NATURAL JOIN nodes
436 WHERE nodes.pep IN %s 436 WHERE nodes.pep IN %s
437 AND node IN %s 437 AND node IN %s
438 AND nodes.access_model in %s 438 AND nodes.access_model in %s
439 AND items.access_model in %s 439 AND items.access_model in %s
440 ORDER BY node_id DESC, item_id DESC""", 440 ORDER BY node_id DESC, items.updated DESC""",
441 (tuple([e.userhost() for e in entities]), 441 (tuple([e.userhost() for e in entities]),
442 nodes, 442 nodes,
443 node_accesses, 443 node_accesses,
444 item_accesses)) 444 item_accesses))
445 d.addCallback(self.formatLastItems) 445 d.addCallback(self.formatLastItems)
1029 else: 1029 else:
1030 log.msg("WARNING: unknown filter: {}".format(filter_.encode('utf-8'))) 1030 log.msg("WARNING: unknown filter: {}".format(filter_.encode('utf-8')))
1031 1031
1032 query.extend(query_filters) 1032 query.extend(query_filters)
1033 1033
1034 return "ORDER BY item_id DESC" 1034 return "ORDER BY items.updated DESC"
1035 1035
1036 def _getItems(self, cursor, authorized_groups, unrestricted, maxItems, ext_data, ids_only): 1036 def _getItems(self, cursor, authorized_groups, unrestricted, maxItems, ext_data, ids_only):
1037 self._checkNodeExists(cursor) 1037 self._checkNodeExists(cursor)
1038 1038
1039 if maxItems == 0: 1039 if maxItems == 0:
1073 args.append(rsm.before) 1073 args.append(rsm.before)
1074 if maxItems is not None: 1074 if maxItems is not None:
1075 # if we have maxItems (i.e. a limit), we need to reverse order 1075 # if we have maxItems (i.e. a limit), we need to reverse order
1076 # in a first query to get the right items 1076 # in a first query to get the right items
1077 query.insert(0,"SELECT * from (") 1077 query.insert(0,"SELECT * from (")
1078 query.append("ORDER BY item_id ASC LIMIT %s) as x") 1078 query.append("ORDER BY updated ASC LIMIT %s) as x")
1079 args.append(maxItems) 1079 args.append(maxItems)
1080 elif rsm.after: 1080 elif rsm.after:
1081 query.append("AND item_id<(SELECT item_id FROM items WHERE item=%s LIMIT 1)") 1081 query.append("AND item_id<(SELECT item_id FROM items WHERE item=%s LIMIT 1)")
1082 args.append(rsm.after) 1082 args.append(rsm.after)
1083 1083