Skip to content

Commit 43b2404

Browse files
t3chguyrichvdh
andauthored
Specify /preview_url requests as low priority (#3609)
* Specify /preview_url requests as low priority * Update src/@types/global.d.ts Co-authored-by: Richard van der Hoff <[email protected]> * Simplify interface --------- Co-authored-by: Richard van der Hoff <[email protected]>
1 parent fed9910 commit 43b2404

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

src/@types/global.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,20 @@ declare global {
9696
// but we still need this for MatrixCall::getRidOfRTXCodecs()
9797
setCodecPreferences(codecs: RTCRtpCodecCapability[]): void;
9898
}
99+
100+
interface RequestInit {
101+
/**
102+
* Specifies the priority of the fetch request relative to other requests of the same type.
103+
* Must be one of the following strings:
104+
* high: A high priority fetch request relative to other requests of the same type.
105+
* low: A low priority fetch request relative to other requests of the same type.
106+
* auto: Automatically determine the priority of the fetch request relative to other requests of the same type (default).
107+
*
108+
* @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attribute
109+
* @see https://github.com/microsoft/TypeScript/issues/54472
110+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility
111+
* Not yet supported in Safari or Firefox
112+
*/
113+
priority?: "high" | "low" | "auto";
114+
}
99115
}

src/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
51285128
undefined,
51295129
{
51305130
prefix: MediaPrefix.R0,
5131+
priority: "low",
51315132
},
51325133
);
51335134
// TODO: Expire the URL preview cache sometimes

src/http-api/fetch.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
222222
method: Method,
223223
url: URL | string,
224224
body?: Body,
225-
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal"> = {},
225+
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal" | "priority"> = {},
226226
): Promise<ResponseType<T, O>> {
227227
const urlForLogs = this.sanitizeUrlForLogs(url);
228228
logger.debug(`FetchHttpApi: --> ${method} ${urlForLogs}`);
@@ -276,6 +276,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
276276
cache: "no-cache",
277277
credentials: "omit", // we send credentials via headers
278278
keepalive: keepAlive,
279+
priority: opts.priority,
279280
});
280281

281282
logger.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${res.status}]`);

src/http-api/interface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface IHttpOpts {
3333
localTimeoutMs?: number;
3434
}
3535

36-
export interface IRequestOpts {
36+
export interface IRequestOpts extends Pick<RequestInit, "priority"> {
3737
/**
3838
* The alternative base url to use.
3939
* If not specified, uses this.opts.baseUrl

0 commit comments

Comments
 (0)