Mercurial > libervia-pubsub
comparison src/pgsql_storage.py @ 393:728b08c0d000
storage (pgsql): fixed storage of multiple items
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 15 Feb 2019 22:06:19 +0100 |
parents | fba96e95e329 |
children | 724e39d596a9 |
comparison
equal
deleted
inserted
replaced
392:3fb2ff438f09 | 393:728b08c0d000 |
---|---|
855 column = 'updated' | 855 column = 'updated' |
856 cols_statmnt.append(column + u' ' + direction) | 856 cols_statmnt.append(column + u' ' + direction) |
857 | 857 |
858 return u"ORDER BY " + u",".join([col for col in cols_statmnt]) | 858 return u"ORDER BY " + u",".join([col for col in cols_statmnt]) |
859 | 859 |
860 def storeItems(self, item_data, publisher): | 860 @defer.inlineCallbacks |
861 return self.dbpool.runInteraction(self._storeItems, item_data, publisher) | 861 def storeItems(self, items_data, publisher): |
862 | 862 # XXX: runInteraction doesn't seem to work when there are several "insert" |
863 def _storeItems(self, cursor, items_data, publisher): | 863 # or "update". |
864 self._checkNodeExists(cursor) | 864 # Before the unpacking was done in _storeItems, but this was causing trouble |
865 # in case of multiple items_data. So this has now be moved here. | |
866 # FIXME: investigate the issue with runInteraction | |
865 for item_data in items_data: | 867 for item_data in items_data: |
866 self._storeItem(cursor, item_data, publisher) | 868 yield self.dbpool.runInteraction(self._storeItems, item_data, publisher) |
869 | |
870 def _storeItems(self, cursor, item_data, publisher): | |
871 self._checkNodeExists(cursor) | |
872 self._storeItem(cursor, item_data, publisher) | |
867 | 873 |
868 def _storeItem(self, cursor, item_data, publisher): | 874 def _storeItem(self, cursor, item_data, publisher): |
869 # first try to insert the item | 875 # first try to insert the item |
870 # - if it fails (conflict), and the item is new and we have serial_ids options, | 876 # - if it fails (conflict), and the item is new and we have serial_ids options, |
871 # current id will be recomputed using next item id query (note that is not perfect, as | 877 # current id will be recomputed using next item id query (note that is not perfect, as |