code: def set_sync_limit(self, limit: int) -> Optional[int]:
          
          try:
              prev_limit = json.loads(self.sync_filter)['room']['timeline']['limit']
          except (json.JSONDecodeError, KeyError):
              prev_limit = None
          self.sync_filter = json.dumps({'room': {'timeline': {'limit': limit}}})
          return prev_limit
docs: Sets the events limit per room for sync and return previous limit