Skip to content

Commit

Permalink
perf: try to improve performance by removing rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthier-th committed Nov 6, 2024
1 parent 64f4610 commit acc3599
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
13 changes: 7 additions & 6 deletions server/api/externalapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RateLimitOptions } from '@server/utils/rateLimit';
import rateLimit from '@server/utils/rateLimit';
// import rateLimit from '@server/utils/rateLimit';
import type NodeCache from 'node-cache';

// 5 minute default TTL (in seconds)
Expand All @@ -26,11 +26,12 @@ class ExternalAPI {
params: Record<string, string> = {},
options: ExternalAPIOptions = {}
) {
if (options.rateLimit) {
this.fetch = rateLimit(fetch, options.rateLimit);
} else {
this.fetch = fetch;
}
// if (options.rateLimit) {
// this.fetch = rateLimit(fetch, options.rateLimit);
// } else {
// this.fetch = fetch;
// }
this.fetch = fetch;

const url = new URL(baseUrl);

Expand Down
17 changes: 9 additions & 8 deletions server/lib/imageproxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logger from '@server/logger';
import type { RateLimitOptions } from '@server/utils/rateLimit';
import rateLimit from '@server/utils/rateLimit';
// import rateLimit from '@server/utils/rateLimit';
import { createHash } from 'crypto';
import { promises } from 'fs';
import mime from 'mime/lite';
Expand Down Expand Up @@ -150,13 +150,14 @@ class ImageProxy {
this.baseUrl = baseUrl;
this.key = key;

if (options.rateLimitOptions) {
this.fetch = rateLimit(fetch, {
...options.rateLimitOptions,
});
} else {
this.fetch = fetch;
}
// if (options.rateLimitOptions) {
// this.fetch = rateLimit(fetch, {
// ...options.rateLimitOptions,
// });
// } else {
// this.fetch = fetch;
// }
this.fetch = fetch;
this.headers = options.headers || null;
}

Expand Down

0 comments on commit acc3599

Please sign in to comment.