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

Commit

Permalink
Merge pull request #1121 from matrix-org/erikj/public_room_paginate
Browse files Browse the repository at this point in the history
Add pagination support to publicRooms
  • Loading branch information
erikjohnston authored Sep 15, 2016
2 parents 264a48a + 1d98cf2 commit e457034
Show file tree
Hide file tree
Showing 18 changed files with 595 additions and 139 deletions.
9 changes: 0 additions & 9 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def read_config(self, config):
self.user_agent_suffix = config.get("user_agent_suffix")
self.use_frozen_dicts = config.get("use_frozen_dicts", False)
self.public_baseurl = config.get("public_baseurl")
self.secondary_directory_servers = config.get("secondary_directory_servers", [])

if self.public_baseurl is not None:
if self.public_baseurl[-1] != '/':
Expand Down Expand Up @@ -142,14 +141,6 @@ def default_config(self, server_name, **kwargs):
# The GC threshold parameters to pass to `gc.set_threshold`, if defined
# gc_thresholds: [700, 10, 10]
# A list of other Home Servers to fetch the public room directory from
# and include in the public room directory of this home server
# This is a temporary stopgap solution to populate new server with a
# list of rooms until there exists a good solution of a decentralized
# room directory.
# secondary_directory_servers:
# - matrix.org
# List of ports that Synapse should listen on, their purpose and their
# configuration.
listeners:
Expand Down
22 changes: 4 additions & 18 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
CodeMessageException, HttpResponseException, SynapseError,
)
from synapse.util import unwrapFirstError
from synapse.util.async import concurrently_execute
from synapse.util.caches.expiringcache import ExpiringCache
from synapse.util.logutils import log_function
from synapse.util.logcontext import preserve_fn, preserve_context_over_deferred
Expand Down Expand Up @@ -719,24 +718,11 @@ def send_leave(self, destinations, pdu):

raise RuntimeError("Failed to send to any server.")

@defer.inlineCallbacks
def get_public_rooms(self, destinations):
results_by_server = {}

@defer.inlineCallbacks
def _get_result(s):
if s == self.server_name:
defer.returnValue()

try:
result = yield self.transport_layer.get_public_rooms(s)
results_by_server[s] = result
except:
logger.exception("Error getting room list from server %r", s)

yield concurrently_execute(_get_result, destinations, 3)
def get_public_rooms(self, destination, limit=None, since_token=None):
if destination == self.server_name:
return

defer.returnValue(results_by_server)
return self.transport_layer.get_public_rooms(destination, limit, since_token)

@defer.inlineCallbacks
def query_auth(self, destination, room_id, event_id, local_auth):
Expand Down
9 changes: 8 additions & 1 deletion synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,19 @@ def send_invite(self, destination, room_id, event_id, content):

@defer.inlineCallbacks
@log_function
def get_public_rooms(self, remote_server):
def get_public_rooms(self, remote_server, limit, since_token):
path = PREFIX + "/publicRooms"

args = {}
if limit:
args["limit"] = [str(limit)]
if since_token:
args["since"] = [since_token]

response = yield self.client.get_json(
destination=remote_server,
path=path,
args=args,
)

defer.returnValue(response)
Expand Down
10 changes: 8 additions & 2 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from synapse.api.urls import FEDERATION_PREFIX as PREFIX
from synapse.api.errors import Codes, SynapseError
from synapse.http.server import JsonResource
from synapse.http.servlet import parse_json_object_from_request
from synapse.http.servlet import (
parse_json_object_from_request, parse_integer_from_args, parse_string_from_args,
)
from synapse.util.ratelimitutils import FederationRateLimiter
from synapse.util.versionstring import get_version_string

Expand Down Expand Up @@ -554,7 +556,11 @@ class PublicRoomList(BaseFederationServlet):

@defer.inlineCallbacks
def on_GET(self, origin, content, query):
data = yield self.room_list_handler.get_local_public_room_list()
limit = parse_integer_from_args(query, "limit", 0)
since_token = parse_string_from_args(query, "since", None)
data = yield self.room_list_handler.get_local_public_room_list(
limit, since_token
)
defer.returnValue((200, data))


Expand Down
Loading

0 comments on commit e457034

Please sign in to comment.