mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Merge pull request #40 from matrix-org/rejections_storage
Rejections storage
This commit is contained in:
commit
9bfc8bf752
@ -20,3 +20,4 @@ class EventContext(object):
|
||||
self.current_state = current_state
|
||||
self.auth_events = auth_events
|
||||
self.state_group = None
|
||||
self.rejected = False
|
||||
|
@ -32,6 +32,8 @@ from .event_federation import EventFederationStore
|
||||
from .pusher import PusherStore
|
||||
from .push_rule import PushRuleStore
|
||||
from .media_repository import MediaRepositoryStore
|
||||
from .rejections import RejectionsStore
|
||||
|
||||
from .state import StateStore
|
||||
from .signatures import SignatureStore
|
||||
from .filtering import FilteringStore
|
||||
@ -65,6 +67,7 @@ SCHEMAS = [
|
||||
"pusher",
|
||||
"media_repository",
|
||||
"filtering",
|
||||
"rejections",
|
||||
]
|
||||
|
||||
|
||||
@ -86,6 +89,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
DirectoryStore, KeyStore, StateStore, SignatureStore,
|
||||
EventFederationStore,
|
||||
MediaRepositoryStore,
|
||||
RejectionsStore,
|
||||
FilteringStore,
|
||||
PusherStore,
|
||||
PushRuleStore
|
||||
@ -231,6 +235,9 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
if not outlier:
|
||||
self._store_state_groups_txn(txn, event, context)
|
||||
|
||||
if context.rejected:
|
||||
self._store_rejections_txn(txn, event.event_id, context.rejected)
|
||||
|
||||
if current_state:
|
||||
txn.execute(
|
||||
"DELETE FROM current_state_events WHERE room_id = ?",
|
||||
@ -269,7 +276,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
or_replace=True,
|
||||
)
|
||||
|
||||
if is_new_state:
|
||||
if is_new_state and not context.rejected:
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
"current_state_events",
|
||||
@ -295,7 +302,7 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||
or_ignore=True,
|
||||
)
|
||||
|
||||
if not backfilled:
|
||||
if not backfilled and not context.rejected:
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table="state_forward_extremities",
|
||||
|
@ -502,10 +502,12 @@ class SQLBaseStore(object):
|
||||
return [e for e in events if e]
|
||||
|
||||
def _get_event_txn(self, txn, event_id, check_redacted=True,
|
||||
get_prev_content=False):
|
||||
get_prev_content=False, allow_rejected=False):
|
||||
sql = (
|
||||
"SELECT internal_metadata, json, r.event_id FROM event_json as e "
|
||||
"SELECT e.internal_metadata, e.json, r.event_id, rej.reason "
|
||||
"FROM event_json as e "
|
||||
"LEFT JOIN redactions as r ON e.event_id = r.redacts "
|
||||
"LEFT JOIN rejections as rej on rej.event_id = e.event_id "
|
||||
"WHERE e.event_id = ? "
|
||||
"LIMIT 1 "
|
||||
)
|
||||
@ -517,13 +519,16 @@ class SQLBaseStore(object):
|
||||
if not res:
|
||||
return None
|
||||
|
||||
internal_metadata, js, redacted = res
|
||||
internal_metadata, js, redacted, rejected_reason = res
|
||||
|
||||
return self._get_event_from_row_txn(
|
||||
txn, internal_metadata, js, redacted,
|
||||
check_redacted=check_redacted,
|
||||
get_prev_content=get_prev_content,
|
||||
)
|
||||
if allow_rejected or not rejected_reason:
|
||||
return self._get_event_from_row_txn(
|
||||
txn, internal_metadata, js, redacted,
|
||||
check_redacted=check_redacted,
|
||||
get_prev_content=get_prev_content,
|
||||
)
|
||||
else:
|
||||
return None
|
||||
|
||||
def _get_event_from_row_txn(self, txn, internal_metadata, js, redacted,
|
||||
check_redacted=True, get_prev_content=False):
|
||||
|
33
synapse/storage/rejections.py
Normal file
33
synapse/storage/rejections.py
Normal file
@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2014, 2015 OpenMarket Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ._base import SQLBaseStore
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RejectionsStore(SQLBaseStore):
|
||||
def _store_rejections_txn(self, txn, event_id, reason):
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table="rejections",
|
||||
values={
|
||||
"event_id": event_id,
|
||||
"reason": reason,
|
||||
"last_failure": self._clock.time_msec(),
|
||||
}
|
||||
)
|
@ -1,4 +1,4 @@
|
||||
/* Copyright 2014 OpenMarket Ltd
|
||||
/* Copyright 2015 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -12,6 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rejections(
|
||||
event_id TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
last_check TEXT NOT NULL,
|
||||
CONSTRAINT ev_id UNIQUE (event_id) ON CONFLICT REPLACE
|
||||
);
|
||||
|
||||
-- Push notification endpoints that users have configured
|
||||
CREATE TABLE IF NOT EXISTS pushers (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
21
synapse/storage/schema/rejections.sql
Normal file
21
synapse/storage/schema/rejections.sql
Normal file
@ -0,0 +1,21 @@
|
||||
/* Copyright 2015 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
CREATE TABLE IF NOT EXISTS rejections(
|
||||
event_id TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
last_check TEXT NOT NULL,
|
||||
CONSTRAINT ev_id UNIQUE (event_id) ON CONFLICT REPLACE
|
||||
);
|
Loading…
Reference in New Issue
Block a user