Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify /preview_url requests as low priority #3609

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ declare global {
// but we still need this for MatrixCall::getRidOfRTXCodecs()
setCodecPreferences(codecs: RTCRtpCodecCapability[]): void;
}

interface RequestInit {
/**
* Specifies the priority of the fetch request relative to other requests of the same type.
* Must be one of the following strings:
* high: A high priority fetch request relative to other requests of the same type.
* low: A low priority fetch request relative to other requests of the same type.
* auto: Automatically determine the priority of the fetch request relative to other requests of the same type (default).
*
* @see https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attribute
* @see https://github.com/microsoft/TypeScript/issues/54472
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#browser_compatibility
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
* Not yet supported in Safari or Firefox
*/
priority?: "high" | "low" | "auto";
}
}
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5128,6 +5128,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
undefined,
{
prefix: MediaPrefix.R0,
priority: "low",
},
);
// TODO: Expire the URL preview cache sometimes
Expand Down
3 changes: 2 additions & 1 deletion src/http-api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
method: Method,
url: URL | string,
body?: Body,
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal"> = {},
opts: Pick<IRequestOpts, "headers" | "json" | "localTimeoutMs" | "keepAlive" | "abortSignal" | "priority"> = {},
): Promise<ResponseType<T, O>> {
const urlForLogs = this.sanitizeUrlForLogs(url);
logger.debug(`FetchHttpApi: --> ${method} ${urlForLogs}`);
Expand Down Expand Up @@ -276,6 +276,7 @@ export class FetchHttpApi<O extends IHttpOpts> {
cache: "no-cache",
credentials: "omit", // we send credentials via headers
keepalive: keepAlive,
priority: opts.priority,
});

logger.debug(`FetchHttpApi: <-- ${method} ${urlForLogs} [${Date.now() - start}ms ${res.status}]`);
Expand Down
2 changes: 1 addition & 1 deletion src/http-api/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface IHttpOpts {
localTimeoutMs?: number;
}

export interface IRequestOpts {
export interface IRequestOpts extends Pick<RequestInit, "priority"> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel like we ought to document what happens to properties that are declared in this way, but whatever

Copy link
Member Author

@t3chguy t3chguy Jul 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess so

/**
* The alternative base url to use.
* If not specified, uses this.opts.baseUrl
Expand Down