Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Improve opentracing support for ResponseCache #11607

Merged
merged 9 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async def upgrade_room(
user_id = requester.user.to_string()

# Check if this room is already being upgraded by another person
for key in self._upgrade_response_cache.pending_result_cache:
for key in self._upgrade_response_cache.keys():
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 is the only reference to ResponseCache.pending_result_cache outside ResponseCache itself.

if key[0] == old_room_id and key[1] != user_id:
# Two different people are trying to upgrade the same room.
# Send the second an error.
Expand Down
13 changes: 12 additions & 1 deletion synapse/util/caches/response_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from typing import Any, Awaitable, Callable, Dict, Generic, Optional, TypeVar
from typing import Any, Awaitable, Callable, Dict, Generic, Iterable, Optional, TypeVar

import attr

Expand Down Expand Up @@ -80,6 +80,17 @@ def size(self) -> int:
def __len__(self) -> int:
return self.size()

def keys(self) -> Iterable[KV]:
"""Get the keys currently in the result cache

Returns both incomplete entries, and (if the timeout on this cache is non-zero),
complete entries which are still in the cache.

Note that the returned iterator is not safe in the face of concurrent execution:
behaviour is undefined if `wrap` is called during iteration.
"""
return self.pending_result_cache.keys()

def get(self, key: KV) -> Optional[defer.Deferred]:
"""Look up the given key.

Expand Down