Add a room visibility stream
This commit is contained in:
parent
ed992ae6ba
commit
baffe96d95
|
@ -113,6 +113,9 @@ class DataStore(RoomMemberStore, RoomStore,
|
||||||
self._device_inbox_id_gen = StreamIdGenerator(
|
self._device_inbox_id_gen = StreamIdGenerator(
|
||||||
db_conn, "device_max_stream_id", "stream_id"
|
db_conn, "device_max_stream_id", "stream_id"
|
||||||
)
|
)
|
||||||
|
self._public_room_id_gen = StreamIdGenerator(
|
||||||
|
db_conn, "public_room_list_stream", "stream_id"
|
||||||
|
)
|
||||||
|
|
||||||
self._transaction_id_gen = IdGenerator(db_conn, "sent_transactions", "id")
|
self._transaction_id_gen = IdGenerator(db_conn, "sent_transactions", "id")
|
||||||
self._state_groups_id_gen = IdGenerator(db_conn, "state_groups", "id")
|
self._state_groups_id_gen = IdGenerator(db_conn, "state_groups", "id")
|
||||||
|
|
|
@ -366,7 +366,7 @@ class EventFederationStore(SQLBaseStore):
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def get_forward_extremeties_for_room_txn(txn):
|
def get_forward_extremeties_for_room_txn(txn):
|
||||||
txn.execute(sql, (room_id, stream_ordering,))
|
txn.execute(sql, (stream_ordering, room_id))
|
||||||
rows = txn.fetchall()
|
rows = txn.fetchall()
|
||||||
return [event_id for event_id, in rows]
|
return [event_id for event_id, in rows]
|
||||||
|
|
||||||
|
|
|
@ -48,14 +48,30 @@ class RoomStore(SQLBaseStore):
|
||||||
StoreError if the room could not be stored.
|
StoreError if the room could not be stored.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
yield self._simple_insert(
|
def store_room_txn(txn, next_id):
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
"rooms",
|
"rooms",
|
||||||
{
|
{
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"creator": room_creator_user_id,
|
"creator": room_creator_user_id,
|
||||||
"is_public": is_public,
|
"is_public": is_public,
|
||||||
},
|
},
|
||||||
desc="store_room",
|
)
|
||||||
|
if is_public:
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
|
table="public_room_list_stream",
|
||||||
|
values={
|
||||||
|
"stream_id": next_id,
|
||||||
|
"room_id": room_id,
|
||||||
|
"visibility": is_public,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
with self._public_room_id_gen.get_next() as next_id:
|
||||||
|
yield self.runInteraction(
|
||||||
|
"store_room_txn",
|
||||||
|
store_room_txn, next_id,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("store_room with room_id=%s failed: %s", room_id, e)
|
logger.error("store_room with room_id=%s failed: %s", room_id, e)
|
||||||
|
@ -77,12 +93,44 @@ class RoomStore(SQLBaseStore):
|
||||||
allow_none=True,
|
allow_none=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
def set_room_is_public(self, room_id, is_public):
|
def set_room_is_public(self, room_id, is_public):
|
||||||
return self._simple_update_one(
|
def set_room_is_public_txn(txn, next_id):
|
||||||
|
self._simple_update_one_txn(
|
||||||
|
txn,
|
||||||
table="rooms",
|
table="rooms",
|
||||||
keyvalues={"room_id": room_id},
|
keyvalues={"room_id": room_id},
|
||||||
updatevalues={"is_public": is_public},
|
updatevalues={"is_public": is_public},
|
||||||
desc="set_room_is_public",
|
)
|
||||||
|
|
||||||
|
entries = self._simple_select_list_txn(
|
||||||
|
txn,
|
||||||
|
table="public_room_list_stream",
|
||||||
|
keyvalues={"room_id": room_id},
|
||||||
|
retcols=("stream_id", "visibility"),
|
||||||
|
)
|
||||||
|
|
||||||
|
entries.sort(key=lambda r: r["stream_id"])
|
||||||
|
|
||||||
|
add_to_stream = True
|
||||||
|
if entries:
|
||||||
|
add_to_stream = bool(entries[-1]["visibility"]) != is_public
|
||||||
|
|
||||||
|
if add_to_stream:
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
|
table="public_room_list_stream",
|
||||||
|
values={
|
||||||
|
"stream_id": next_id,
|
||||||
|
"room_id": room_id,
|
||||||
|
"visibility": is_public,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
with self._public_room_id_gen.get_next() as next_id:
|
||||||
|
yield self.runInteraction(
|
||||||
|
"set_room_is_public",
|
||||||
|
set_room_is_public_txn, next_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_public_room_ids(self):
|
def get_public_room_ids(self):
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/* Copyright 2016 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 public_room_list_stream (
|
||||||
|
stream_id BIGINT NOT NULL,
|
||||||
|
room_id TEXT NOT NULL,
|
||||||
|
visibility BOOLEAN NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO public_room_list_stream (stream_id, room_id, visibility)
|
||||||
|
SELECT 1, room_id, is_public FROM rooms
|
||||||
|
WHERE is_public = CAST(1 AS BOOLEAN);
|
||||||
|
|
||||||
|
CREATE INDEX public_room_list_stream_idx on public_room_list_stream(
|
||||||
|
stream_id
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX public_room_list_stream_rm_idx on public_room_list_stream(
|
||||||
|
room_id, stream_id
|
||||||
|
);
|
Loading…
Reference in New Issue