You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.6 KiB

  1. # Copyright 2015, 2016 OpenMarket Ltd
  2. # Copyright 2018 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from typing import Any, Iterable
  16. from synapse.replication.tcp.streams import PushRulesStream
  17. from synapse.storage.databases.main.push_rule import PushRulesWorkerStore
  18. from .events import SlavedEventStore
  19. class SlavedPushRuleStore(SlavedEventStore, PushRulesWorkerStore):
  20. def get_max_push_rules_stream_id(self) -> int:
  21. return self._push_rules_stream_id_gen.get_current_token()
  22. def process_replication_rows(
  23. self, stream_name: str, instance_name: str, token: int, rows: Iterable[Any]
  24. ) -> None:
  25. if stream_name == PushRulesStream.NAME:
  26. self._push_rules_stream_id_gen.advance(instance_name, token)
  27. for row in rows:
  28. self.get_push_rules_for_user.invalidate((row.user_id,))
  29. self.get_push_rules_enabled_for_user.invalidate((row.user_id,))
  30. self.push_rules_stream_cache.entity_has_changed(row.user_id, token)
  31. return super().process_replication_rows(stream_name, instance_name, token, rows)