diff --git a/src/components/etke.cc/ServerStatusBadge.tsx b/src/components/etke.cc/ServerStatusBadge.tsx index 4d0a461..ea0ae58 100644 --- a/src/components/etke.cc/ServerStatusBadge.tsx +++ b/src/components/etke.cc/ServerStatusBadge.tsx @@ -48,7 +48,7 @@ const StyledBadge = styled(Badge, { shouldForwardProp: (prop) => !['badgeColor', // every 5 minutes const SERVER_STATUS_INTERVAL_TIME = 5 * 60 * 1000; // every 5 seconds -const SERVER_CURRENT_PROCCESS_INTERVAL_TIME = 5 * 1000; +const SERVER_CURRENT_PROCCESS_INTERVAL_TIME = 35 * 1000; const useServerStatus = () => { const [serverStatus, setServerStatus] = useStore("serverStatus", { ok: false, success: false, host: "", results: [] }); diff --git a/src/resources/users.tsx b/src/resources/users.tsx index 28524b1..e0e5246 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..cfa3e9d 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,36 @@ 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 jsonData = []; + let total = 0; + + if (CACHED_MANY_REF[ref]) { + jsonData = CACHED_MANY_REF[ref]["data"].slice(from, from + perPage); + total = CACHED_MANY_REF[ref]["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[ref] = { 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, }; },