Skip to content

Commit

Permalink
✨ Allow for cache busting on flaw requests
Browse files Browse the repository at this point in the history
  • Loading branch information
superbuggy committed Jan 24, 2025
1 parent 470a4cd commit c7e213a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/composables/useRelatedFlawTrackers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export function useRelatedFlawTrackers(
await new Promise(resolve => setTimeout(resolve, 2000));
try {
for (const flaw of selectedRelatedFlaws.value) {
const fetchedFlaw = await getFlaw(flaw.uuid);
const fetchedFlaw = await getFlaw(flaw.uuid, true);
const index = relatedFlaws.value.findIndex(({ uuid }) => uuid === flaw.uuid);
if (index !== -1) {
relatedFlaws.value[index].affects = fetchedFlaw.affects;
Expand Down
3 changes: 2 additions & 1 deletion src/services/FlawService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ export async function getRelatedFlaws(affects: ZodAffectType[]): Promise<ZodFlaw
return relatedFlaws;
}

export async function getFlaw(uuidOrCve: string): Promise<ZodFlawType> {
export async function getFlaw(uuidOrCve: string, breakCache?: boolean): Promise<ZodFlawType> {
return osidbFetch({
method: 'get',
url: `/osidb/api/v1/flaws/${uuidOrCve}`,
cache: breakCache ? 'no-cache' : 'default',
params: {
include_meta_attr: 'bz_id',
include_history: 'true',
Expand Down
6 changes: 6 additions & 0 deletions src/services/OsidbAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ export type OsidbFetchCallbacks = {
// afterFetch?: (response: Response) => Promise<void> | void;
};

type CacheOptions = 'default' | 'force-cache' | 'no-cache' | 'only-if-cached' | 'reload';

export type OsidbGetFetchOptions = {
cache?: CacheOptions;
data?: never;
method: 'GET' | 'get';
params?: Record<string, any>;
url: string;
};

export type OsidbPutPostFetchOptions = {
cache?: CacheOptions;
data?: Record<string, any>;
method: 'POST' | 'post' | 'PUT' | 'put';
params?: Record<string, any>;
url: string;
};

export type OsidbDeleteFetchOptions = {
cache?: never;
data?: Record<string, any> | Record<string, any>[] | string[];
method: 'DELETE' | 'delete';
params?: never;
Expand Down Expand Up @@ -62,6 +67,7 @@ export async function osidbFetch(config: OsidbFetchOptions, factoryOptions?: Osi
headers: await osimRequestHeaders(),
mode: 'cors',
credentials: 'include',
cache: config?.cache,
body,
});
} catch (e) {
Expand Down

0 comments on commit c7e213a

Please sign in to comment.