diff options
author | Erik Johnston <erik@matrix.org> | 2015-07-14 10:49:24 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-07-14 10:49:24 +0100 |
commit | baa55fb69e88bc95f9ea603ca9d1cd758cba5187 (patch) | |
tree | 58040d05bde26aa28b128bc8784b1006426f2aea /synapse/storage/signatures.py | |
parent | Close, but no cigar. (diff) | |
parent | Remove commented out code (diff) | |
download | synapse-baa55fb69e88bc95f9ea603ca9d1cd758cba5187.tar.xz |
Merge pull request #193 from matrix-org/erikj/bulk_persist_event
Add bulk insert events API
Diffstat (limited to 'synapse/storage/signatures.py')
-rw-r--r-- | synapse/storage/signatures.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/synapse/storage/signatures.py b/synapse/storage/signatures.py index f051828630..4f15e534b4 100644 --- a/synapse/storage/signatures.py +++ b/synapse/storage/signatures.py @@ -18,6 +18,7 @@ from twisted.internet import defer from _base import SQLBaseStore from syutil.base64util import encode_base64 +from synapse.crypto.event_signing import compute_event_reference_hash class SignatureStore(SQLBaseStore): @@ -101,23 +102,26 @@ class SignatureStore(SQLBaseStore): txn.execute(query, (event_id, )) return {k: v for k, v in txn.fetchall()} - def _store_event_reference_hash_txn(self, txn, event_id, algorithm, - hash_bytes): + def _store_event_reference_hashes_txn(self, txn, events): """Store a hash for a PDU Args: txn (cursor): - event_id (str): Id for the Event. - algorithm (str): Hashing algorithm. - hash_bytes (bytes): Hash function output bytes. + events (list): list of Events. """ - self._simple_insert_txn( + + vals = [] + for event in events: + ref_alg, ref_hash_bytes = compute_event_reference_hash(event) + vals.append({ + "event_id": event.event_id, + "algorithm": ref_alg, + "hash": buffer(ref_hash_bytes), + }) + + self._simple_insert_many_txn( txn, - "event_reference_hashes", - { - "event_id": event_id, - "algorithm": algorithm, - "hash": buffer(hash_bytes), - }, + table="event_reference_hashes", + values=vals, ) def _get_event_signatures_txn(self, txn, event_id): |