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

pull/9/head
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:
d = copy.copy(pdu_tuple.pdu_entry._asdict())
d["origin_server_ts"] = d.pop("ts")
d["content"] = json.loads(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["ts"] = cols.pop("origin_server_ts")
logger.debug("Persisting: %s", repr(cols))
if pdu.is_state:

View File

@ -354,6 +354,7 @@ class SQLBaseStore(object):
d.pop("stream_ordering", None)
d.pop("topological_ordering", None)
d.pop("processed", None)
d["origin_server_ts"] = d.pop("ts", 0)
d.update(json.loads(row_dict["unrecognized_keys"]))
d["content"] = json.loads(d["content"])
@ -361,7 +362,7 @@ class SQLBaseStore(object):
if "age_ts" not in d:
# 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(
etype=d["type"],

View File

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

View File

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

View File

@ -16,7 +16,7 @@
CREATE TABLE IF NOT EXISTS received_transactions(
transaction_id TEXT,
origin TEXT,
origin_server_ts INTEGER,
ts INTEGER,
response_code INTEGER,
response_json TEXT,
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,
response_code INTEGER DEFAULT 0,
response_json TEXT,
origin_server_ts INTEGER
ts INTEGER
);
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))
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
previous transaction id list.
@ -109,8 +110,8 @@ class TransactionStore(SQLBaseStore):
transaction_id, destination, origin_server_ts, pdu_list
)
def _prep_send_transaction(self, txn, transaction_id, destination, origin_server_ts,
pdu_list):
def _prep_send_transaction(self, txn, transaction_id, destination,
origin_server_ts, pdu_list):
# First we find out what the prev_txs should be.
# Since we know that we are only sending one transaction at a time,
@ -131,7 +132,7 @@ class TransactionStore(SQLBaseStore):
None,
transaction_id=transaction_id,
destination=destination,
origin_server_ts=origin_server_ts,
ts=origin_server_ts,
response_code=0,
response_json=None
))
@ -251,7 +252,7 @@ class ReceivedTransactionsTable(Table):
fields = [
"transaction_id",
"origin",
"origin_server_ts",
"ts",
"response_code",
"response_json",
"has_been_referenced",
@ -267,7 +268,7 @@ class SentTransactions(Table):
"id",
"transaction_id",
"destination",
"origin_server_ts",
"ts",
"response_code",
"response_json",
]

View File

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