This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve ServerNoticeServlet to avoid duplicate requests #10679
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve ServerNoticeServlet to avoid duplicate requests and add unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,27 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
from typing import Optional | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from synapse.api.constants import EventTypes, Membership, RoomCreationPreset | ||
from synapse.events import EventBase | ||
from synapse.types import UserID, create_requester | ||
from synapse.util.caches.descriptors import cached | ||
|
||
if TYPE_CHECKING: | ||
from synapse.server import HomeServer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
SERVER_NOTICE_ROOM_TAG = "m.server_notice" | ||
|
||
|
||
class ServerNoticesManager: | ||
def __init__(self, hs): | ||
def __init__(self, hs: "HomeServer"): | ||
""" | ||
|
||
Args: | ||
hs (synapse.server.HomeServer): | ||
hs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just remove the entire docstring, as its pointless at this point |
||
""" | ||
|
||
self._store = hs.get_datastore() | ||
|
@@ -58,6 +61,7 @@ async def send_notice( | |
event_content: dict, | ||
type: str = EventTypes.Message, | ||
state_key: Optional[str] = None, | ||
txn_id: Optional[str] = None, | ||
) -> EventBase: | ||
"""Send a notice to the given user | ||
|
||
|
@@ -68,6 +72,7 @@ async def send_notice( | |
event_content: content of event to send | ||
type: type of event | ||
is_state_event: Is the event a state event | ||
txn_id: The transaction ID. | ||
""" | ||
room_id = await self.get_or_create_notice_room_for_user(user_id) | ||
await self.maybe_invite_user_to_room(user_id, room_id) | ||
|
@@ -90,7 +95,7 @@ async def send_notice( | |
event_dict["state_key"] = state_key | ||
|
||
event, _ = await self._event_creation_handler.create_and_send_nonmember_event( | ||
requester, event_dict, ratelimit=False | ||
requester, event_dict, ratelimit=False, txn_id=txn_id | ||
) | ||
return event | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention is to use
*_id
for the string representations of the IDs. We may as well also pull out auser_id
since we use it below (I'm not a fan of doingbody["user_id"]
multiple times as it makes it look like we haven't validated it)