comparison sat_pubsub/pgsql_storage.py @ 457:7c9792f934a2

psql: use `created` colum to sort by creation: `item_id` was used to sort by creation because it correspond to it and it's slighly more efficient, but #398 raises the use case of manually modified database to import items. The column has been changed to suit this use case, and `item_id` is now always added as last order, in case of date conflicts. This patch extends a contribution from Stephen Paul Weber (Singpolyma) from the ticket mentioned below. fix: 398
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 18:56:42 +0200
parents b52ebc45b8e3
children f520ac3164b0
comparison
equal deleted inserted replaced
456:b52ebc45b8e3 457:7c9792f934a2
892 if not keys: 892 if not keys:
893 return f"ORDER BY updated {direction}, item_id {direction}" 893 return f"ORDER BY updated {direction}, item_id {direction}"
894 cols_statmnt = [] 894 cols_statmnt = []
895 for key in keys: 895 for key in keys:
896 if key == 'creation': 896 if key == 'creation':
897 column = 'item_id' # could work with items.created too 897 column = 'created'
898 elif key == 'modification': 898 elif key == 'modification':
899 column = 'updated' 899 column = 'updated'
900 else: 900 else:
901 log.msg("WARNING: Unknown order by key: {key}".format(key=key)) 901 log.msg("WARNING: Unknown order by key: {key}".format(key=key))
902 column = 'updated' 902 column = 'updated'
903 cols_statmnt.append(f"{column} {direction}") 903 cols_statmnt.append(f"{column} {direction}")
904 904
905 if len(cols_statmnt) == 1 and column != "item_id": 905 cols_statmnt.append(f"item_id {direction}")
906 cols_statmnt.append(f"item_id {direction}")
907 return "ORDER BY " + ",".join([col for col in cols_statmnt]) 906 return "ORDER BY " + ",".join([col for col in cols_statmnt])
908 907
909 @defer.inlineCallbacks 908 @defer.inlineCallbacks
910 def storeItems(self, items_data, publisher): 909 def storeItems(self, items_data, publisher):
911 # XXX: runInteraction doesn't seem to work when there are several "insert" 910 # XXX: runInteraction doesn't seem to work when there are several "insert"