keep 'origin_server_ts' as 'ts' in the database to avoid needlessly updating schema

This commit is contained in:
Mark Haines 2014-10-17 17:31:48 +01:00
parent f5cf7ac25b
commit 82c5820767
8 changed files with 18 additions and 13 deletions

View file

@ -118,6 +118,7 @@ class Pdu(JsonEncodedObject):
""" """
if pdu_tuple: if pdu_tuple:
d = copy.copy(pdu_tuple.pdu_entry._asdict()) d = copy.copy(pdu_tuple.pdu_entry._asdict())
d["origin_server_ts"] = d.pop("ts")
d["content"] = json.loads(d["content_json"]) d["content"] = json.loads(d["content_json"])
del d["content_json"] del d["content_json"]

View file

@ -155,6 +155,8 @@ class DataStore(RoomMemberStore, RoomStore,
cols["unrecognized_keys"] = json.dumps(unrec_keys) cols["unrecognized_keys"] = json.dumps(unrec_keys)
cols["ts"] = cols.pop("origin_server_ts")
logger.debug("Persisting: %s", repr(cols)) logger.debug("Persisting: %s", repr(cols))
if pdu.is_state: if pdu.is_state:

View file

@ -354,6 +354,7 @@ class SQLBaseStore(object):
d.pop("stream_ordering", None) d.pop("stream_ordering", None)
d.pop("topological_ordering", None) d.pop("topological_ordering", None)
d.pop("processed", None) d.pop("processed", None)
d["origin_server_ts"] = d.pop("ts", 0)
d.update(json.loads(row_dict["unrecognized_keys"])) d.update(json.loads(row_dict["unrecognized_keys"]))
d["content"] = json.loads(d["content"]) d["content"] = json.loads(d["content"])
@ -361,7 +362,7 @@ class SQLBaseStore(object):
if "age_ts" not in d: if "age_ts" not in d:
# For compatibility # For compatibility
d["age_ts"] = d["origin_server_ts"] if "origin_server_ts" in d else 0 d["age_ts"] = d.get("origin_server_ts", 0)
return self.event_factory.create_event( return self.event_factory.create_event(
etype=d["type"], etype=d["type"],

View file

@ -789,7 +789,7 @@ class PdusTable(Table):
"origin", "origin",
"context", "context",
"pdu_type", "pdu_type",
"origin_server_ts", "ts",
"depth", "depth",
"is_state", "is_state",
"content_json", "content_json",

View file

@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS pdus(
origin TEXT, origin TEXT,
context TEXT, context TEXT,
pdu_type TEXT, pdu_type TEXT,
origin_server_ts INTEGER, ts INTEGER,
depth INTEGER DEFAULT 0 NOT NULL, depth INTEGER DEFAULT 0 NOT NULL,
is_state BOOL, is_state BOOL,
content_json TEXT, content_json TEXT,

View file

@ -16,7 +16,7 @@
CREATE TABLE IF NOT EXISTS received_transactions( CREATE TABLE IF NOT EXISTS received_transactions(
transaction_id TEXT, transaction_id TEXT,
origin TEXT, origin TEXT,
origin_server_ts INTEGER, ts INTEGER,
response_code INTEGER, response_code INTEGER,
response_json TEXT, response_json TEXT,
has_been_referenced BOOL default 0, -- Whether thishas been referenced by a prev_tx has_been_referenced BOOL default 0, -- Whether thishas been referenced by a prev_tx
@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS sent_transactions(
destination TEXT, destination TEXT,
response_code INTEGER DEFAULT 0, response_code INTEGER DEFAULT 0,
response_json TEXT, response_json TEXT,
origin_server_ts INTEGER ts INTEGER
); );
CREATE INDEX IF NOT EXISTS sent_transaction_dest ON sent_transactions(destination); CREATE INDEX IF NOT EXISTS sent_transaction_dest ON sent_transactions(destination);

View file

@ -87,7 +87,8 @@ class TransactionStore(SQLBaseStore):
txn.execute(query, (code, response_json, transaction_id, origin)) txn.execute(query, (code, response_json, transaction_id, origin))
def prep_send_transaction(self, transaction_id, destination, origin_server_ts, pdu_list): def prep_send_transaction(self, transaction_id, destination,
origin_server_ts, pdu_list):
"""Persists an outgoing transaction and calculates the values for the """Persists an outgoing transaction and calculates the values for the
previous transaction id list. previous transaction id list.
@ -109,8 +110,8 @@ class TransactionStore(SQLBaseStore):
transaction_id, destination, origin_server_ts, pdu_list transaction_id, destination, origin_server_ts, pdu_list
) )
def _prep_send_transaction(self, txn, transaction_id, destination, origin_server_ts, def _prep_send_transaction(self, txn, transaction_id, destination,
pdu_list): origin_server_ts, pdu_list):
# First we find out what the prev_txs should be. # First we find out what the prev_txs should be.
# Since we know that we are only sending one transaction at a time, # Since we know that we are only sending one transaction at a time,
@ -131,7 +132,7 @@ class TransactionStore(SQLBaseStore):
None, None,
transaction_id=transaction_id, transaction_id=transaction_id,
destination=destination, destination=destination,
origin_server_ts=origin_server_ts, ts=origin_server_ts,
response_code=0, response_code=0,
response_json=None response_json=None
)) ))
@ -251,7 +252,7 @@ class ReceivedTransactionsTable(Table):
fields = [ fields = [
"transaction_id", "transaction_id",
"origin", "origin",
"origin_server_ts", "ts",
"response_code", "response_code",
"response_json", "response_json",
"has_been_referenced", "has_been_referenced",
@ -267,7 +268,7 @@ class SentTransactions(Table):
"id", "id",
"transaction_id", "transaction_id",
"destination", "destination",
"origin_server_ts", "ts",
"response_code", "response_code",
"response_json", "response_json",
] ]

View file

@ -99,7 +99,7 @@ class FederationTestCase(unittest.TestCase):
origin="red", origin="red",
context="my-context", context="my-context",
pdu_type="m.topic", pdu_type="m.topic",
origin_server_ts=123456789000, ts=123456789000,
depth=1, depth=1,
is_state=True, is_state=True,
content_json='{"topic":"The topic"}', content_json='{"topic":"The topic"}',
@ -134,7 +134,7 @@ class FederationTestCase(unittest.TestCase):
origin="red", origin="red",
context="my-context", context="my-context",
pdu_type="m.text", pdu_type="m.text",
origin_server_ts=123456789001, ts=123456789001,
depth=1, depth=1,
content_json='{"text":"Here is the message"}', content_json='{"text":"Here is the message"}',
) )