mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 16:05:00 -04:00
Shuffle persist event data store functions. (#7440)
The aim here is to get to a stage where we have a `PersistEventStore` that holds all the write methods used during event persistence, so that we can take that class out of the `DataStore` mixin and instansiate it separately. This will allow us to instansiate it on processes other than master, while also ensuring it is only available on processes that are configured to write to events stream. This is a bit of an architectural change, where we end up with multiple classes per data store (rather than one per data store we have now). We end up having: 1. Storage classes that provide high level APIs that can talk to multiple data stores. 2. Data store modules that consist of classes that must point at the same database instance. 3. Classes in a data store that can be instantiated on processes depending on config.
This commit is contained in:
parent
7ee24c5674
commit
782e4e64df
19 changed files with 1399 additions and 1258 deletions
|
@ -13,23 +13,13 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import six
|
||||
|
||||
from unpaddedbase64 import encode_base64
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.crypto.event_signing import compute_event_reference_hash
|
||||
from synapse.storage._base import SQLBaseStore
|
||||
from synapse.util.caches.descriptors import cached, cachedList
|
||||
|
||||
# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
|
||||
# despite being deprecated and removed in favor of memoryview
|
||||
if six.PY2:
|
||||
db_binary_type = six.moves.builtins.buffer
|
||||
else:
|
||||
db_binary_type = memoryview
|
||||
|
||||
|
||||
class SignatureWorkerStore(SQLBaseStore):
|
||||
@cached()
|
||||
|
@ -79,23 +69,3 @@ class SignatureWorkerStore(SQLBaseStore):
|
|||
|
||||
class SignatureStore(SignatureWorkerStore):
|
||||
"""Persistence for event signatures and hashes"""
|
||||
|
||||
def _store_event_reference_hashes_txn(self, txn, events):
|
||||
"""Store a hash for a PDU
|
||||
Args:
|
||||
txn (cursor):
|
||||
events (list): list of Events.
|
||||
"""
|
||||
|
||||
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": db_binary_type(ref_hash_bytes),
|
||||
}
|
||||
)
|
||||
|
||||
self.db.simple_insert_many_txn(txn, table="event_reference_hashes", values=vals)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue