summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/__init__.py23
-rw-r--r--synapse/storage/_base.py18
-rw-r--r--synapse/storage/room.py8
-rw-r--r--synapse/storage/roommember.py6
-rw-r--r--synapse/storage/schema/deletions.sql7
-rw-r--r--synapse/storage/schema/delta/v4.sql11
-rw-r--r--synapse/storage/schema/im.sql2
-rw-r--r--synapse/storage/schema/redactions.sql8
-rw-r--r--synapse/storage/stream.py18
9 files changed, 52 insertions, 49 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index accb4359bd..fcf8b4d183 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -24,7 +24,7 @@ from synapse.api.events.room import (
     RoomAddStateLevelEvent,
     RoomSendEventLevelEvent,
     RoomOpsPowerLevelsEvent,
-    RoomDeletionEvent,
+    RoomRedactionEvent,
 )
 
 from synapse.util.logutils import log_function
@@ -57,7 +57,7 @@ SCHEMAS = [
     "presence",
     "im",
     "room_aliases",
-    "deletions",
+    "redactions",
 ]
 
 
@@ -184,8 +184,8 @@ class DataStore(RoomMemberStore, RoomStore,
             self._store_send_event_level(txn, event)
         elif event.type == RoomOpsPowerLevelsEvent.TYPE:
             self._store_ops_level(txn, event)
-        elif event.type == RoomDeletionEvent.TYPE:
-            self._store_deletion(txn, event)
+        elif event.type == RoomRedactionEvent.TYPE:
+            self._store_redaction(txn, event)
 
         vals = {
             "topological_ordering": event.depth,
@@ -207,7 +207,7 @@ class DataStore(RoomMemberStore, RoomStore,
         unrec = {
             k: v
             for k, v in event.get_full_dict().items()
-            if k not in vals.keys() and k not in ["deleted", "pruned_because"]
+            if k not in vals.keys() and k not in ["redacted", "redacted_because"]
         }
         vals["unrecognized_keys"] = json.dumps(unrec)
 
@@ -245,25 +245,26 @@ class DataStore(RoomMemberStore, RoomStore,
                 }
             )
 
-    def _store_deletion(self, txn, event):
+    def _store_redaction(self, txn, event):
         txn.execute(
-            "INSERT INTO deletions (event_id, deletes) VALUES (?,?) OR IGNORE",
-            (event.event_id, event.deletes)
+            "INSERT OR IGNORE INTO redactions "
+            "(event_id, redacts) VALUES (?,?)",
+            (event.event_id, event.redacts)
         )
 
     @defer.inlineCallbacks
     def get_current_state(self, room_id, event_type=None, state_key=""):
         del_sql = (
-            "SELECT event_id FROM deletions WHERE deletes = e.event_id"
+            "SELECT event_id FROM redactions WHERE redacts = e.event_id"
         )
 
         sql = (
-            "SELECT e.*, (%(deleted)s) AS deleted FROM events as e "
+            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
             "INNER JOIN current_state_events as c ON e.event_id = c.event_id "
             "INNER JOIN state_events as s ON e.event_id = s.event_id "
             "WHERE c.room_id = ? "
         ) % {
-            "deleted": del_sql,
+            "redacted": del_sql,
         }
 
         if event_type:
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 444e7628d1..889de2bedc 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -383,14 +383,14 @@ class SQLBaseStore(object):
                     prev = self._parse_event_from_row(prevs[0])
                     ev.prev_content = prev.content
 
-            if not hasattr(ev, "deleted"):
-                logger.debug("Doesn't have deleted key: %s", ev)
-                ev.deleted = self._has_been_deleted_txn(txn, ev)
+            if not hasattr(ev, "redacted"):
+                logger.debug("Doesn't have redacted key: %s", ev)
+                ev.redacted = self._has_been_redacted_txn(txn, ev)
 
-            if ev.deleted:
-                # Get the deletion event.
+            if ev.redacted:
+                # Get the redaction event.
                 sql = "SELECT * FROM events WHERE event_id = ?"
-                txn.execute(sql, (ev.deleted,))
+                txn.execute(sql, (ev.redacted,))
 
                 del_evs = self._parse_events_txn(
                     txn, self.cursor_to_dict(txn)
@@ -398,12 +398,12 @@ class SQLBaseStore(object):
 
                 if del_evs:
                     prune_event(ev)
-                    ev.pruned_because = del_evs[0]
+                    ev.redacted_because = del_evs[0]
 
         return events
 
-    def _has_been_deleted_txn(self, txn, event):
-        sql = "SELECT event_id FROM deletions WHERE deletes = ?"
+    def _has_been_redacted_txn(self, txn, event):
+        sql = "SELECT event_id FROM redactions WHERE redacts = ?"
         txn.execute(sql, (event.event_id,))
         result = txn.fetchone()
         return result[0] if result else None
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index b1239a0f1a..8cd46334cf 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -27,7 +27,7 @@ import logging
 logger = logging.getLogger(__name__)
 
 
-OpsLevel = collections.namedtuple("OpsLevel", ("ban_level", "kick_level", "delete_level"))
+OpsLevel = collections.namedtuple("OpsLevel", ("ban_level", "kick_level", "redact_level"))
 
 
 class RoomStore(SQLBaseStore):
@@ -189,7 +189,7 @@ class RoomStore(SQLBaseStore):
 
     def _get_ops_levels(self, txn, room_id):
         sql = (
-            "SELECT ban_level, kick_level, delete_level "
+            "SELECT ban_level, kick_level, redact_level "
             "FROM room_ops_levels as r "
             "INNER JOIN current_state_events as c "
             "ON r.event_id = c.event_id "
@@ -327,8 +327,8 @@ class RoomStore(SQLBaseStore):
         if "ban_level" in event.content:
             content["ban_level"] = event.content["ban_level"]
 
-        if "delete_level" in event.content:
-            content["delete_level"] = event.content["delete_level"]
+        if "redact_level" in event.content:
+            content["redact_level"] = event.content["redact_level"]
 
         self._simple_insert_txn(
             txn,
diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py
index 97222da571..84c462330b 100644
--- a/synapse/storage/roommember.py
+++ b/synapse/storage/roommember.py
@@ -183,18 +183,18 @@ class RoomMemberStore(SQLBaseStore):
 
     def _get_members_query_txn(self, txn, where_clause, where_values):
         del_sql = (
-            "SELECT event_id FROM deletions WHERE deletes = e.event_id"
+            "SELECT event_id FROM redactions WHERE redacts = e.event_id"
         )
 
         sql = (
-            "SELECT e.*, (%(deleted)s) AS deleted FROM events as e "
+            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
             "INNER JOIN room_memberships as m "
             "ON e.event_id = m.event_id "
             "INNER JOIN current_state_events as c "
             "ON m.event_id = c.event_id "
             "WHERE %(where)s "
         ) % {
-            "deleted": del_sql,
+            "redacted": del_sql,
             "where": where_clause,
         }
 
diff --git a/synapse/storage/schema/deletions.sql b/synapse/storage/schema/deletions.sql
deleted file mode 100644
index 2e2635317a..0000000000
--- a/synapse/storage/schema/deletions.sql
+++ /dev/null
@@ -1,7 +0,0 @@
-CREATE TABLE IF NOT EXISTS deletions (
-    event_id TEXT NOT NULL,
-    deletes TEXT NOT NULL
-);
-
-CREATE INDEX IF NOT EXISTS deletions_event_id ON deletions (event_id);
-CREATE INDEX IF NOT EXISTS deletions_deletes ON deletions (deletes);
diff --git a/synapse/storage/schema/delta/v4.sql b/synapse/storage/schema/delta/v4.sql
index fc8bb5ad84..25d2ead450 100644
--- a/synapse/storage/schema/delta/v4.sql
+++ b/synapse/storage/schema/delta/v4.sql
@@ -1,11 +1,12 @@
-CREATE TABLE IF NOT EXISTS deletions (
+CREATE TABLE IF NOT EXISTS redactions (
     event_id TEXT NOT NULL,
-    deletes TEXT NOT NULL
+    redacts TEXT NOT NULL,
+    CONSTRAINT ev_uniq UNIQUE (event_id)
 );
 
-CREATE INDEX IF NOT EXISTS deletions_event_id ON deletions (event_id);
-CREATE INDEX IF NOT EXISTS deletions_deletes ON deletions (deletes);
+CREATE INDEX IF NOT EXISTS redactions_event_id ON redactions (event_id);
+CREATE INDEX IF NOT EXISTS redactions_redacts ON redactions (redacts);
 
-ALTER TABLE room_ops_levels ADD COLUMN delete_level INTEGER;
+ALTER TABLE room_ops_levels ADD COLUMN redact_level INTEGER;
 
 PRAGMA user_version = 4;
diff --git a/synapse/storage/schema/im.sql b/synapse/storage/schema/im.sql
index 649d54b813..3aa83f5c8c 100644
--- a/synapse/storage/schema/im.sql
+++ b/synapse/storage/schema/im.sql
@@ -151,7 +151,7 @@ CREATE TABLE IF NOT EXISTS room_ops_levels(
     room_id TEXT NOT NULL,
     ban_level INTEGER,
     kick_level INTEGER,
-    delete_level INTEGER
+    redact_level INTEGER
 );
 
 CREATE INDEX IF NOT EXISTS room_ops_levels_event_id ON room_ops_levels(event_id);
diff --git a/synapse/storage/schema/redactions.sql b/synapse/storage/schema/redactions.sql
new file mode 100644
index 0000000000..4c2829d05d
--- /dev/null
+++ b/synapse/storage/schema/redactions.sql
@@ -0,0 +1,8 @@
+CREATE TABLE IF NOT EXISTS redactions (
+    event_id TEXT NOT NULL,
+    redacts TEXT NOT NULL,
+    CONSTRAINT ev_uniq UNIQUE (event_id)
+);
+
+CREATE INDEX IF NOT EXISTS redactions_event_id ON redactions (event_id);
+CREATE INDEX IF NOT EXISTS redactions_redacts ON redactions (redacts);
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index aaac0aae30..91baa18319 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -158,7 +158,7 @@ class StreamStore(SQLBaseStore):
         )
 
         del_sql = (
-            "SELECT event_id FROM deletions WHERE deletes = e.event_id"
+            "SELECT event_id FROM redactions WHERE redacts = e.event_id"
         )
 
         if limit:
@@ -175,14 +175,14 @@ class StreamStore(SQLBaseStore):
             return
 
         sql = (
-            "SELECT *, (%(deleted)s) AS deleted FROM events AS e WHERE "
+            "SELECT *, (%(redacted)s) AS redacted FROM events AS e WHERE "
             "((room_id IN (%(current)s)) OR "
             "(event_id IN (%(invites)s))) "
             "AND e.stream_ordering > ? AND e.stream_ordering <= ? "
             "AND e.outlier = 0 "
             "ORDER BY stream_ordering ASC LIMIT %(limit)d "
         ) % {
-            "deleted": del_sql,
+            "redacted": del_sql,
             "current": current_room_membership_sql,
             "invites": membership_sql,
             "limit": limit
@@ -230,15 +230,15 @@ class StreamStore(SQLBaseStore):
             limit_str = ""
 
         del_sql = (
-            "SELECT event_id FROM deletions WHERE deletes = events.event_id"
+            "SELECT event_id FROM redactions WHERE redacts = events.event_id"
         )
 
         sql = (
-            "SELECT *, (%(deleted)s) AS deleted FROM events "
+            "SELECT *, (%(redacted)s) AS redacted FROM events "
             "WHERE outlier = 0 AND room_id = ? AND %(bounds)s "
             "ORDER BY topological_ordering %(order)s, stream_ordering %(order)s %(limit)s "
         ) % {
-            "deleted": del_sql,
+            "redacted": del_sql,
             "bounds": bounds,
             "order": order,
             "limit": limit_str
@@ -272,15 +272,15 @@ class StreamStore(SQLBaseStore):
         # TODO (erikj): Handle compressed feedback
 
         del_sql = (
-            "SELECT event_id FROM deletions WHERE deletes = events.event_id"
+            "SELECT event_id FROM redactions WHERE redacts = events.event_id"
         )
 
         sql = (
-            "SELECT *, (%(deleted)s) AS deleted FROM events "
+            "SELECT *, (%(redacted)s) AS redacted FROM events "
             "WHERE room_id = ? AND stream_ordering <= ? "
             "ORDER BY topological_ordering DESC, stream_ordering DESC LIMIT ? "
         ) % {
-            "deleted": del_sql,
+            "redacted": del_sql,
         }
 
         rows = yield self._execute_and_decode(