diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 4fcef45e93..d38d613450 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -44,7 +44,6 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
def __init__(self, hs):
super(DataStore, self).__init__(hs)
self.event_factory = hs.get_event_factory()
- self.hs = hs
@defer.inlineCallbacks
def persist_event(self, event):
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 03537b7e3b..489b6bd171 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -28,8 +28,10 @@ logger = logging.getLogger(__name__)
class SQLBaseStore(object):
def __init__(self, hs):
+ self.hs = hs
self._db_pool = hs.get_db_pool()
self.event_factory = hs.get_event_factory()
+ self._clock = hs.get_clock()
def cursor_to_dict(self, cursor):
"""Converts a SQL cursor into an list of dicts.
diff --git a/synapse/storage/pdu.py b/synapse/storage/pdu.py
index 202d7f6cb6..13adc581e1 100644
--- a/synapse/storage/pdu.py
+++ b/synapse/storage/pdu.py
@@ -168,7 +168,7 @@ class PduStore(SQLBaseStore):
return self._get_pdu_tuples(txn, txn.fetchall())
- def get_pagination(self, context, pdu_list, limit):
+ def get_backfill(self, context, pdu_list, limit):
"""Get a list of Pdus for a given topic that occured before (and
including) the pdus in pdu_list. Return a list of max size `limit`.
@@ -182,12 +182,12 @@ class PduStore(SQLBaseStore):
list: A list of PduTuples
"""
return self._db_pool.runInteraction(
- self._get_paginate, context, pdu_list, limit
+ self._get_backfill, context, pdu_list, limit
)
- def _get_paginate(self, txn, context, pdu_list, limit):
+ def _get_backfill(self, txn, context, pdu_list, limit):
logger.debug(
- "paginate: %s, %s, %s",
+ "backfill: %s, %s, %s",
context, repr(pdu_list), limit
)
@@ -213,7 +213,7 @@ class PduStore(SQLBaseStore):
new_front = []
for pdu_id, origin in front:
logger.debug(
- "_paginate_interaction: i=%s, o=%s",
+ "_backfill_interaction: i=%s, o=%s",
pdu_id, origin
)
@@ -224,7 +224,7 @@ class PduStore(SQLBaseStore):
for row in txn.fetchall():
logger.debug(
- "_paginate_interaction: got i=%s, o=%s",
+ "_backfill_interaction: got i=%s, o=%s",
*row
)
new_front.append(row)
@@ -262,7 +262,7 @@ class PduStore(SQLBaseStore):
def update_min_depth_for_context(self, context, depth):
"""Update the minimum `depth` of the given context, which is the line
- where we stop paginating backwards on.
+ on which we stop backfilling backwards.
Args:
context (str)
@@ -320,9 +320,9 @@ class PduStore(SQLBaseStore):
return [(row[0], row[1], row[2]) for row in results]
def get_oldest_pdus_in_context(self, context):
- """Get a list of Pdus that we paginated beyond yet (and haven't seen).
- This list is used when we want to paginate backwards and is the list we
- send to the remote server.
+ """Get a list of Pdus that we haven't backfilled beyond yet (and haven't
+ seen). This list is used when we want to backfill backwards and is the
+ list we send to the remote server.
Args:
txn
diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py
index 6f5b042c25..23b6d1694e 100644
--- a/synapse/storage/presence.py
+++ b/synapse/storage/presence.py
@@ -35,7 +35,7 @@ class PresenceStore(SQLBaseStore):
return self._simple_select_one(
table="presence",
keyvalues={"user_id": user_localpart},
- retcols=["state", "status_msg"],
+ retcols=["state", "status_msg", "mtime"],
)
def set_presence_state(self, user_localpart, new_state):
@@ -43,7 +43,8 @@ class PresenceStore(SQLBaseStore):
table="presence",
keyvalues={"user_id": user_localpart},
updatevalues={"state": new_state["state"],
- "status_msg": new_state["status_msg"]},
+ "status_msg": new_state["status_msg"],
+ "mtime": self._clock.time_msec()},
retcols=["state"],
)
diff --git a/synapse/storage/schema/presence.sql b/synapse/storage/schema/presence.sql
index b22e3ba863..b1081d3aab 100644
--- a/synapse/storage/schema/presence.sql
+++ b/synapse/storage/schema/presence.sql
@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS presence(
user_id INTEGER NOT NULL,
state INTEGER,
status_msg TEXT,
+ mtime INTEGER, -- miliseconds since last state change
FOREIGN KEY(user_id) REFERENCES users(id)
);
|