Skip to content
Snippets Groups Projects
Unverified Commit 80e0e1f3 authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

Only fetch thread participation for events with threads. (#12228)

We fetch the thread summary in two phases:

1. The summary that is shared by all users (count of messages and latest event).
2. Whether the requesting user has participated in the thread.

There's no use in attempting step 2 for events which did not return a summary
from step 1.
parent 2177e356
Branches
Tags
No related merge requests found
Fix a bug introduced in v1.53.0 where an unnecessary query could be performed when fetching bundled aggregations for threads.
...@@ -857,7 +857,9 @@ class RelationsWorkerStore(SQLBaseStore): ...@@ -857,7 +857,9 @@ class RelationsWorkerStore(SQLBaseStore):
summaries = await self._get_thread_summaries(events_by_id.keys()) summaries = await self._get_thread_summaries(events_by_id.keys())
# Only fetch participated for a limited selection based on what had # Only fetch participated for a limited selection based on what had
# summaries. # summaries.
participated = await self._get_threads_participated(summaries.keys(), user_id) participated = await self._get_threads_participated(
[event_id for event_id, summary in summaries.items() if summary], user_id
)
for event_id, summary in summaries.items(): for event_id, summary in summaries.items():
if summary: if summary:
thread_count, latest_thread_event, edit = summary thread_count, latest_thread_event, edit = summary
......
This diff is collapsed.
...@@ -54,13 +54,18 @@ from twisted.internet.interfaces import ( ...@@ -54,13 +54,18 @@ from twisted.internet.interfaces import (
ITransport, ITransport,
) )
from twisted.python.failure import Failure from twisted.python.failure import Failure
from twisted.test.proto_helpers import AccumulatingProtocol, MemoryReactorClock from twisted.test.proto_helpers import (
AccumulatingProtocol,
MemoryReactor,
MemoryReactorClock,
)
from twisted.web.http_headers import Headers from twisted.web.http_headers import Headers
from twisted.web.resource import IResource from twisted.web.resource import IResource
from twisted.web.server import Request, Site from twisted.web.server import Request, Site
from synapse.config.database import DatabaseConnectionConfig from synapse.config.database import DatabaseConnectionConfig
from synapse.http.site import SynapseRequest from synapse.http.site import SynapseRequest
from synapse.logging.context import ContextResourceUsage
from synapse.server import HomeServer from synapse.server import HomeServer
from synapse.storage import DataStore from synapse.storage import DataStore
from synapse.storage.engines import PostgresEngine, create_engine from synapse.storage.engines import PostgresEngine, create_engine
...@@ -88,18 +93,19 @@ class TimedOutException(Exception): ...@@ -88,18 +93,19 @@ class TimedOutException(Exception):
""" """
@attr.s @attr.s(auto_attribs=True)
class FakeChannel: class FakeChannel:
""" """
A fake Twisted Web Channel (the part that interfaces with the A fake Twisted Web Channel (the part that interfaces with the
wire). wire).
""" """
site = attr.ib(type=Union[Site, "FakeSite"]) site: Union[Site, "FakeSite"]
_reactor = attr.ib() _reactor: MemoryReactor
result = attr.ib(type=dict, default=attr.Factory(dict)) result: dict = attr.Factory(dict)
_ip = attr.ib(type=str, default="127.0.0.1") _ip: str = "127.0.0.1"
_producer: Optional[Union[IPullProducer, IPushProducer]] = None _producer: Optional[Union[IPullProducer, IPushProducer]] = None
resource_usage: Optional[ContextResourceUsage] = None
@property @property
def json_body(self): def json_body(self):
...@@ -168,6 +174,8 @@ class FakeChannel: ...@@ -168,6 +174,8 @@ class FakeChannel:
def requestDone(self, _self): def requestDone(self, _self):
self.result["done"] = True self.result["done"] = True
if isinstance(_self, SynapseRequest):
self.resource_usage = _self.logcontext.get_resource_usage()
def getPeer(self): def getPeer(self):
# We give an address so that getClientIP returns a non null entry, # We give an address so that getClientIP returns a non null entry,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment