@@ -1935,6 +1935,65 @@ async def set_room_is_public_appservice(
19351935 desc = "set_room_is_public_appservice_false" ,
19361936 )
19371937
1938+ async def has_auth_chain_index (self , room_id : str ) -> bool :
1939+ """Check if the room has (or can have) a chain cover index.
1940+
1941+ Defaults to True if we don't have an entry in `rooms` table nor any
1942+ events for the room.
1943+ """
1944+
1945+ has_auth_chain_index = await self .db_pool .simple_select_one_onecol (
1946+ table = "rooms" ,
1947+ keyvalues = {"room_id" : room_id },
1948+ retcol = "has_auth_chain_index" ,
1949+ desc = "has_auth_chain_index" ,
1950+ allow_none = True ,
1951+ )
1952+
1953+ if has_auth_chain_index :
1954+ return True
1955+
1956+ # It's possible that we already have events for the room in our DB
1957+ # without a corresponding room entry. If we do then we don't want to
1958+ # mark the room as having an auth chain cover index.
1959+ max_ordering = await self .db_pool .simple_select_one_onecol (
1960+ table = "events" ,
1961+ keyvalues = {"room_id" : room_id },
1962+ retcol = "MAX(stream_ordering)" ,
1963+ allow_none = True ,
1964+ desc = "has_auth_chain_index_fallback" ,
1965+ )
1966+
1967+ return max_ordering is None
1968+
1969+ async def maybe_store_room_on_outlier_membership (
1970+ self , room_id : str , room_version : RoomVersion
1971+ ) -> None :
1972+ """
1973+ When we receive an invite or any other event over federation that may relate to a room
1974+ we are not in, store the version of the room if we don't already know the room version.
1975+ """
1976+ # It's possible that we already have events for the room in our DB
1977+ # without a corresponding room entry. If we do then we don't want to
1978+ # mark the room as having an auth chain cover index.
1979+ has_auth_chain_index = await self .has_auth_chain_index (room_id )
1980+
1981+ await self .db_pool .simple_upsert (
1982+ desc = "maybe_store_room_on_outlier_membership" ,
1983+ table = "rooms" ,
1984+ keyvalues = {"room_id" : room_id },
1985+ values = {},
1986+ insertion_values = {
1987+ "room_version" : room_version .identifier ,
1988+ "is_public" : False ,
1989+ # We don't worry about setting the `creator` here because
1990+ # we don't process any messages in a room while a user is
1991+ # invited (only after the join).
1992+ "creator" : "" ,
1993+ "has_auth_chain_index" : has_auth_chain_index ,
1994+ },
1995+ )
1996+
19381997
19391998class _BackgroundUpdates :
19401999 REMOVE_TOMESTONED_ROOMS_BG_UPDATE = "remove_tombstoned_rooms_from_directory"
@@ -2186,37 +2245,6 @@ def _get_rooms(txn: LoggingTransaction) -> List[str]:
21862245
21872246 return len (rooms )
21882247
2189- async def has_auth_chain_index (self , room_id : str ) -> bool :
2190- """Check if the room has (or can have) a chain cover index.
2191-
2192- Defaults to True if we don't have an entry in `rooms` table nor any
2193- events for the room.
2194- """
2195-
2196- has_auth_chain_index = await self .db_pool .simple_select_one_onecol (
2197- table = "rooms" ,
2198- keyvalues = {"room_id" : room_id },
2199- retcol = "has_auth_chain_index" ,
2200- desc = "has_auth_chain_index" ,
2201- allow_none = True ,
2202- )
2203-
2204- if has_auth_chain_index :
2205- return True
2206-
2207- # It's possible that we already have events for the room in our DB
2208- # without a corresponding room entry. If we do then we don't want to
2209- # mark the room as having an auth chain cover index.
2210- max_ordering = await self .db_pool .simple_select_one_onecol (
2211- table = "events" ,
2212- keyvalues = {"room_id" : room_id },
2213- retcol = "MAX(stream_ordering)" ,
2214- allow_none = True ,
2215- desc = "has_auth_chain_index_fallback" ,
2216- )
2217-
2218- return max_ordering is None
2219-
22202248 async def _background_populate_room_depth_min_depth2 (
22212249 self , progress : JsonDict , batch_size : int
22222250 ) -> int :
@@ -2567,34 +2595,6 @@ def _write_partial_state_rooms_join_event_id(
25672595 updatevalues = {"join_event_id" : join_event_id },
25682596 )
25692597
2570- async def maybe_store_room_on_outlier_membership (
2571- self , room_id : str , room_version : RoomVersion
2572- ) -> None :
2573- """
2574- When we receive an invite or any other event over federation that may relate to a room
2575- we are not in, store the version of the room if we don't already know the room version.
2576- """
2577- # It's possible that we already have events for the room in our DB
2578- # without a corresponding room entry. If we do then we don't want to
2579- # mark the room as having an auth chain cover index.
2580- has_auth_chain_index = await self .has_auth_chain_index (room_id )
2581-
2582- await self .db_pool .simple_upsert (
2583- desc = "maybe_store_room_on_outlier_membership" ,
2584- table = "rooms" ,
2585- keyvalues = {"room_id" : room_id },
2586- values = {},
2587- insertion_values = {
2588- "room_version" : room_version .identifier ,
2589- "is_public" : False ,
2590- # We don't worry about setting the `creator` here because
2591- # we don't process any messages in a room while a user is
2592- # invited (only after the join).
2593- "creator" : "" ,
2594- "has_auth_chain_index" : has_auth_chain_index ,
2595- },
2596- )
2597-
25982598 async def add_event_report (
25992599 self ,
26002600 room_id : str ,
0 commit comments