Replace all timeouts with AbortSignal

This commit is contained in:
Alex Gleason
2023-12-22 10:38:48 -06:00
parent 6d6e3bcecc
commit ad0aaf97dd
10 changed files with 35 additions and 40 deletions

View File

@@ -8,7 +8,7 @@ import { getAuthor, getFollowedPubkeys, getFollows } from '@/queries.ts';
import { booleanParamSchema, fileSchema } from '@/schema.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { uploadFile } from '@/upload.ts';
import { isFollowing, lookupAccount, nostrNow, Time } from '@/utils.ts';
import { isFollowing, lookupAccount, nostrNow } from '@/utils.ts';
import { paginated, paginationSchema, parseBody } from '@/utils/web.ts';
import { createEvent } from '@/utils/web.ts';
import { renderEventAccounts } from '@/views.ts';
@@ -258,7 +258,7 @@ const favouritesController: AppController = async (c) => {
const events7 = await mixer.getFilters(
[{ kinds: [7], authors: [pubkey], ...params }],
{ timeout: Time.seconds(1) },
{ signal: AbortSignal.timeout(1000) },
);
const ids = events7
@@ -266,7 +266,7 @@ const favouritesController: AppController = async (c) => {
.filter((id): id is string => !!id);
const events1 = await mixer.getFilters([{ kinds: [1], ids, relations: ['author', 'event_stats', 'author_stats'] }], {
timeout: Time.seconds(1),
signal: AbortSignal.timeout(1000),
});
const statuses = await Promise.all(events1.map((event) => renderStatus(event, c.get('pubkey'))));

View File

@@ -1,6 +1,5 @@
import { type AppController } from '@/app.ts';
import * as mixer from '@/mixer.ts';
import { Time } from '@/utils.ts';
import { paginated, paginationSchema } from '@/utils/web.ts';
import { renderNotification } from '@/views/mastodon/notifications.ts';
@@ -10,7 +9,7 @@ const notificationsController: AppController = async (c) => {
const events = await mixer.getFilters(
[{ kinds: [1], '#p': [pubkey], since, until }],
{ timeout: Time.seconds(3) },
{ signal: AbortSignal.timeout(3000) },
);
const statuses = await Promise.all(events.map((event) => renderNotification(event, pubkey)));

View File

@@ -5,7 +5,7 @@ import { type DittoFilter } from '@/filter.ts';
import * as mixer from '@/mixer.ts';
import { booleanParamSchema } from '@/schema.ts';
import { nostrIdSchema } from '@/schemas/nostr.ts';
import { dedupeEvents, Time } from '@/utils.ts';
import { dedupeEvents } from '@/utils.ts';
import { lookupNip05Cached } from '@/utils/nip05.ts';
import { renderAccount } from '@/views/mastodon/accounts.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
@@ -93,9 +93,9 @@ function typeToKinds(type: SearchQuery['type']): number[] {
}
/** Resolve a searched value into an event, if applicable. */
async function lookupEvent(query: SearchQuery): Promise<Event | undefined> {
async function lookupEvent(query: SearchQuery, signal = AbortSignal.timeout(1000)): Promise<Event | undefined> {
const filters = await getLookupFilters(query);
const [event] = await mixer.getFilters(filters, { limit: 1, timeout: Time.seconds(1) });
const [event] = await mixer.getFilters(filters, { limit: 1, signal });
return event;
}

View File

@@ -3,7 +3,6 @@ import { type DittoFilter } from '@/filter.ts';
import * as mixer from '@/mixer.ts';
import { getFeedPubkeys } from '@/queries.ts';
import { booleanParamSchema } from '@/schema.ts';
import { Time } from '@/utils.ts';
import { paginated, paginationSchema } from '@/utils/web.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
@@ -33,10 +32,10 @@ const hashtagTimelineController: AppController = (c) => {
};
/** Render statuses for timelines. */
async function renderStatuses(c: AppContext, filters: DittoFilter<1>[]) {
async function renderStatuses(c: AppContext, filters: DittoFilter<1>[], signal = AbortSignal.timeout(1000)) {
const events = await mixer.getFilters(
filters.map((filter) => ({ ...filter, relations: ['author', 'event_stats', 'author_stats'] })),
{ timeout: Time.seconds(1) },
{ signal },
);
if (!events.length) {