Skip to content

Commit

Permalink
Revert "Store cache control headers, change index order"
Browse files Browse the repository at this point in the history
This reverts commit 0dd2fd4.

Original index order was required
  • Loading branch information
synzen committed Dec 31, 2024
1 parent 0dd2fd4 commit 109f0fb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 42 deletions.
19 changes: 0 additions & 19 deletions services/feed-requests/migrations/Migration20241231120419.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class Response {
type: 'json',
nullable: true,
})
headers?: Record<string, string> | null;
headers?: {
etag?: string;
lastModified?: string;
} | null;

@Property({
type: 'timestamp with time zone',
Expand Down
33 changes: 25 additions & 8 deletions services/feed-requests/src/feed-fetcher/feed-fetcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ interface FetchOptions {
interface FetchResponse {
ok: boolean;
status: number;
headers: Map<string, string>;
headers: Map<'etag' | 'last-modified' | 'server' | 'content-type', string>;
text: () => Promise<string>;
arrayBuffer: () => Promise<ArrayBuffer>;
}
Expand Down Expand Up @@ -135,11 +135,19 @@ export class FeedFetcherService {
request: Request;
decodedResponseText: string | null | undefined;
} | null> {
const logDebug =
url ===
'https://www.clanaod.net/forums/external.php?type=RSS2&forumids=102';

const request = await this.partitionedRequestsStore.getLatestRequest(
lookupKey || url,
);

if (!request) {
if (logDebug) {
logger.warn(`Running debug on schedule: no request was found`);
}

return null;
}

Expand All @@ -154,6 +162,13 @@ export class FeedFetcherService {
).toString()
: '';

if (logDebug) {
logger.warn(
`Running debug on schedule: got cache key ${request.response.redisCacheKey}`,
{ text },
);
}

return {
request,
decodedResponseText: text,
Expand Down Expand Up @@ -217,13 +232,20 @@ export class FeedFetcherService {
request.status = RequestStatus.BAD_STATUS_CODE;
}

const etag = res.headers.get('etag');
const lastModified = res.headers.get('last-modified');

const response = new Response();
response.createdAt = request.createdAt;
response.statusCode = res.status;
response.headers = {};

for (const [key, val] of res.headers.entries()) {
response.headers[key] = val;
if (etag) {
response.headers.etag = etag;
}

if (lastModified) {
response.headers.lastModified = lastModified;
}

let text: string | null = null;
Expand Down Expand Up @@ -437,11 +459,6 @@ export class FeedFetcherService {
convertHeaderValue(normalizedHeaders.get('last-modified')),
);
headers.set('server', convertHeaderValue(normalizedHeaders.get('server')));
headers.set('date', convertHeaderValue(normalizedHeaders.get('date')));
headers.set(
'cache-control',
convertHeaderValue(normalizedHeaders.get('cache-control')),
);

return {
headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,11 @@ export default class PartitionedRequestsStoreService {

async getLatestOkRequest(
lookupKey: string,
opts?: {
fields?: Record<'response_headers', boolean>;
},
): Promise<null | {
createdAt: Date;
responseHeaders?: Record<string, string>;
}> {
): Promise<null | { createdAt: Date }> {
const em = this.orm.em.getConnection();

const [result] = await em.execute(
`SELECT created_at ${
opts?.fields?.response_headers ? ', response_headers' : ''
} FROM request_partitioned
`SELECT created_at FROM request_partitioned
WHERE lookup_key = ?
AND status = 'OK'
ORDER BY created_at DESC
Expand All @@ -144,10 +136,7 @@ export default class PartitionedRequestsStoreService {
return null;
}

return {
createdAt: new Date(result.created_at),
responseHeaders: result.response_headers,
};
return { createdAt: new Date(result.created_at) };
}

async countFailedRequests(lookupKey: string, since?: Date) {
Expand Down

0 comments on commit 109f0fb

Please sign in to comment.