changeset 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 26e46a3043e5
children 9a787881b824
files src/pgsql_storage.py
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/pgsql_storage.py	Sun Mar 04 21:06:23 2018 +0100
+++ b/src/pgsql_storage.py	Thu Jan 03 20:31:03 2019 +0100
@@ -437,7 +437,7 @@
                                     AND node IN %s
                                     AND nodes.access_model in %s
                                     AND items.access_model in %s
-                                    ORDER BY node_id DESC, item_id DESC""",
+                                    ORDER BY node_id DESC, items.updated DESC""",
                                  (tuple([e.userhost() for e in entities]),
                                   nodes,
                                   node_accesses,
@@ -1031,7 +1031,7 @@
 
         query.extend(query_filters)
 
-        return "ORDER BY item_id DESC"
+        return "ORDER BY items.updated DESC"
 
     def _getItems(self, cursor, authorized_groups, unrestricted, maxItems, ext_data, ids_only):
         self._checkNodeExists(cursor)
@@ -1075,7 +1075,7 @@
                     # if we have maxItems (i.e. a limit), we need to reverse order
                     # in a first query to get the right items
                     query.insert(0,"SELECT * from (")
-                    query.append("ORDER BY item_id ASC LIMIT %s) as x")
+                    query.append("ORDER BY updated ASC LIMIT %s) as x")
                     args.append(maxItems)
             elif rsm.after:
                 query.append("AND item_id<(SELECT item_id FROM items WHERE item=%s LIMIT 1)")