Skip to content
Open
22 changes: 21 additions & 1 deletion synapse/storage/databases/main/delayed_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

import logging
from http import HTTPStatus
from typing import NewType, Optional, Union
from typing import TYPE_CHECKING, NewType, Optional, Union

import attr

from synapse.api.errors import NotFoundError, SynapseError, cs_error
from synapse.storage._base import SQLBaseStore, db_to_json
from synapse.storage.database import (
DatabasePool,
LoggingDatabaseConnection,
LoggingTransaction,
make_in_list_sql_clause,
)
Expand All @@ -29,6 +31,9 @@
from synapse.util import stringutils
from synapse.util.json import json_encoder

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -59,6 +64,21 @@ class DelayedEventDetails(EventDetails):


class DelayedEventsStore(SQLBaseStore):
def __init__(
self,
database: DatabasePool,
db_conn: LoggingDatabaseConnection,
hs: "HomeServer",
):
super().__init__(database, db_conn, hs)

self.db_pool.updates.register_background_index_update(
update_name="delayed_events_finalised_ts",
index_name="delayed_events_finalised_ts",
table="delayed_events",
columns=("finalised_ts",),
)

async def get_delayed_events_stream_pos(self) -> int:
"""
Gets the stream position of the background process to watch for state events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ ALTER TABLE delayed_events ADD COLUMN finalised_error bytea;
ALTER TABLE delayed_events ADD COLUMN finalised_event_id TEXT;
ALTER TABLE delayed_events ADD COLUMN finalised_ts BIGINT;

CREATE INDEX delayed_events_finalised_ts ON delayed_events (finalised_ts);
INSERT INTO background_updates (update_name, progress_json) VALUES
('delayed_events_finalised_ts', '{}');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had to be added to pass the check-schema-delta job.

Given that this is an index on a new, null-by-default column, is there really a need to add it in the background?

Loading