diff --git a/src/resources/users.tsx b/src/resources/users.tsx index 28524b1..35175b1 100644 --- a/src/resources/users.tsx +++ b/src/resources/users.tsx @@ -497,7 +497,7 @@ export const UserEdit = (props: EditProps) => { target="user_id" label={false} pagination={} - perPage={50} + perPage={10} sort={{ field: "created_ts", order: "DESC" }} > }> @@ -516,7 +516,7 @@ export const UserEdit = (props: EditProps) => { } path="rooms"> - + }> "/rooms/" + id + "/show"} bulkActionButtons={false}> diff --git a/src/synapse/dataProvider.ts b/src/synapse/dataProvider.ts index 5cade98..a099d76 100644 --- a/src/synapse/dataProvider.ts +++ b/src/synapse/dataProvider.ts @@ -16,6 +16,8 @@ import { import { returnMXID } from "../utils/mxid"; import { MatrixError, displayError } from "../utils/error"; +const CACHED_MANY_REF: Record = {}; + // Adds the access token to all requests const jsonClient = async (url: string, options: Options = {}) => { const token = localStorage.getItem("access_token"); @@ -706,18 +708,37 @@ const baseDataProvider: SynapseDataProvider = { dir: getSearchOrder(order), }; + + const homeserver = localStorage.getItem("base_url"); if (!homeserver || !(resource in resourceMap)) throw Error("Homeserver not set"); const res = resourceMap[resource]; const ref = res.reference(params.id); - const endpoint_url = `${homeserver}${ref.endpoint}?${new URLSearchParams(filterUndefined(query)).toString()}`; - const { json } = await jsonClient(endpoint_url); + const endpoint_url = `${homeserver}${ref.endpoint}?${new URLSearchParams(filterUndefined(query)).toString()}`; + let CACHE_KEY = ref.endpoint; + let jsonData = []; + let total = 0; + + if (CACHED_MANY_REF[CACHE_KEY]) { + jsonData = CACHED_MANY_REF[CACHE_KEY]["data"].slice(from, from + perPage); + total = CACHED_MANY_REF[CACHE_KEY]["total"]; + } else { + const { json } = await jsonClient(endpoint_url); + jsonData = json[res.data] + total = res.total(json, from, perPage); + if (resource === "joined_rooms") { + // cache will be applied only for joined_rooms + CACHED_MANY_REF[CACHE_KEY] = { data: jsonData, total: total }; + jsonData = jsonData.slice(from, from + perPage); + } + } + return { - data: json[res.data].map(res.map), - total: res.total(json, from, perPage), + data: jsonData.map(res.map), + total: total, }; },