mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
refactor: remove unused methods/routes, fix some gallery invalidation issues
This commit is contained in:
@@ -427,61 +427,12 @@ export const imagesApi = api.injectEndpoints({
|
||||
},
|
||||
}),
|
||||
}),
|
||||
/**
|
||||
* Get counts for starred and unstarred image collections
|
||||
*/
|
||||
getImageCollectionCounts: build.query<
|
||||
paths['/api/v1/images/collections/counts']['get']['responses']['200']['content']['application/json'],
|
||||
paths['/api/v1/images/collections/counts']['get']['parameters']['query']
|
||||
>({
|
||||
query: (queryArgs) => ({
|
||||
url: buildImagesUrl('collections/counts', queryArgs),
|
||||
method: 'GET',
|
||||
}),
|
||||
providesTags: ['ImageCollectionCounts', 'FetchOnReconnect'],
|
||||
}),
|
||||
/**
|
||||
* Get images from a specific collection (starred or unstarred)
|
||||
*/
|
||||
getImageCollection: build.query<
|
||||
paths['/api/v1/images/collections/{collection}']['get']['responses']['200']['content']['application/json'],
|
||||
paths['/api/v1/images/collections/{collection}']['get']['parameters']['path'] &
|
||||
paths['/api/v1/images/collections/{collection}']['get']['parameters']['query']
|
||||
>({
|
||||
query: ({ collection, ...queryArgs }) => ({
|
||||
url: buildImagesUrl(`collections/${collection}`, queryArgs),
|
||||
method: 'GET',
|
||||
}),
|
||||
providesTags: (result, error, { collection, board_id, categories }) => {
|
||||
const cacheKey = `${collection}-${board_id || 'all'}-${categories?.join(',') || 'all'}`;
|
||||
return [
|
||||
{ type: 'ImageCollection', id: collection },
|
||||
{ type: 'ImageCollection', id: cacheKey },
|
||||
'FetchOnReconnect',
|
||||
];
|
||||
},
|
||||
async onQueryStarted(_, { dispatch, queryFulfilled }) {
|
||||
// Populate the getImageDTO cache with these images, similar to listImages
|
||||
const res = await queryFulfilled;
|
||||
const imageDTOs = res.data.items;
|
||||
const updates: Param0<typeof imagesApi.util.upsertQueryEntries> = [];
|
||||
for (const imageDTO of imageDTOs) {
|
||||
updates.push({
|
||||
endpointName: 'getImageDTO',
|
||||
arg: imageDTO.image_name,
|
||||
value: imageDTO,
|
||||
});
|
||||
}
|
||||
dispatch(imagesApi.util.upsertQueryEntries(updates));
|
||||
},
|
||||
}),
|
||||
/**
|
||||
* Get ordered list of image names for selection operations
|
||||
*/
|
||||
getImageNames: build.query<
|
||||
string[],
|
||||
{
|
||||
image_origin?: 'internal' | 'external' | null;
|
||||
categories?: ImageCategory[] | null;
|
||||
is_intermediate?: boolean | null;
|
||||
board_id?: string | null;
|
||||
@@ -493,46 +444,11 @@ export const imagesApi = api.injectEndpoints({
|
||||
url: buildImagesUrl('names', queryArgs),
|
||||
method: 'GET',
|
||||
}),
|
||||
providesTags: ['ImageNameList', 'FetchOnReconnect'],
|
||||
}),
|
||||
/**
|
||||
* Get paginated images with starred first (unified list)
|
||||
*/
|
||||
getUnifiedImageList: build.query<
|
||||
ListImagesResponse,
|
||||
{
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
image_origin?: 'internal' | 'external' | null;
|
||||
categories?: ImageCategory[] | null;
|
||||
is_intermediate?: boolean | null;
|
||||
board_id?: string | null;
|
||||
search_term?: string | null;
|
||||
order_dir?: SQLiteDirection;
|
||||
}
|
||||
>({
|
||||
query: (queryArgs) => ({
|
||||
url: getListImagesUrl({ ...queryArgs, starred_first: true }),
|
||||
method: 'GET',
|
||||
}),
|
||||
providesTags: (result, error, { board_id, categories }) => [
|
||||
{ type: 'ImageList', id: getListImagesUrl({ board_id, categories }) },
|
||||
providesTags: (result, error, queryArgs) => [
|
||||
'ImageNameList',
|
||||
'FetchOnReconnect',
|
||||
{ type: 'ImageNameList', id: stableHash(queryArgs) },
|
||||
],
|
||||
async onQueryStarted(_, { dispatch, queryFulfilled }) {
|
||||
// Populate the getImageDTO cache with these images
|
||||
const res = await queryFulfilled;
|
||||
const imageDTOs = res.data.items;
|
||||
const updates: Param0<typeof imagesApi.util.upsertQueryEntries> = [];
|
||||
for (const imageDTO of imageDTOs) {
|
||||
updates.push({
|
||||
endpointName: 'getImageDTO',
|
||||
arg: imageDTO.image_name,
|
||||
value: imageDTO,
|
||||
});
|
||||
}
|
||||
dispatch(imagesApi.util.upsertQueryEntries(updates));
|
||||
},
|
||||
}),
|
||||
}),
|
||||
});
|
||||
@@ -555,11 +471,7 @@ export const {
|
||||
useStarImagesMutation,
|
||||
useUnstarImagesMutation,
|
||||
useBulkDownloadImagesMutation,
|
||||
useGetImageCollectionCountsQuery,
|
||||
useGetImageCollectionQuery,
|
||||
useLazyGetImageCollectionQuery,
|
||||
useGetImageNamesQuery,
|
||||
useGetUnifiedImageListQuery,
|
||||
} = imagesApi;
|
||||
|
||||
/**
|
||||
|
||||
@@ -752,7 +752,7 @@ export type paths = {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/images/collections/counts": {
|
||||
"/api/v1/images/names": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
@@ -760,30 +760,10 @@ export type paths = {
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* Get Image Collection Counts
|
||||
* @description Gets counts for starred and unstarred image collections
|
||||
* Get Image Names
|
||||
* @description Gets ordered list of all image names (starred first, then unstarred)
|
||||
*/
|
||||
get: operations["get_image_collection_counts"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/images/collections/{collection}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* Get Image Collection
|
||||
* @description Gets images from a specific collection (starred or unstarred)
|
||||
*/
|
||||
get: operations["get_image_collection"];
|
||||
get: operations["get_image_names"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
@@ -9844,19 +9824,6 @@ export type components = {
|
||||
*/
|
||||
type: "img_channel_offset";
|
||||
};
|
||||
/** ImageCollectionCounts */
|
||||
ImageCollectionCounts: {
|
||||
/**
|
||||
* Starred Count
|
||||
* @description The number of starred images in the collection.
|
||||
*/
|
||||
starred_count: number;
|
||||
/**
|
||||
* Unstarred Count
|
||||
* @description The number of unstarred images in the collection.
|
||||
*/
|
||||
unstarred_count: number;
|
||||
};
|
||||
/**
|
||||
* Image Collection Primitive
|
||||
* @description A collection of image primitive values
|
||||
@@ -23728,17 +23695,21 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
get_image_collection_counts: {
|
||||
get_image_names: {
|
||||
parameters: {
|
||||
query?: {
|
||||
/** @description The origin of images to count. */
|
||||
/** @description The origin of images to list. */
|
||||
image_origin?: components["schemas"]["ResourceOrigin"] | null;
|
||||
/** @description The categories of image to include. */
|
||||
categories?: components["schemas"]["ImageCategory"][] | null;
|
||||
/** @description Whether to include intermediate images. */
|
||||
/** @description Whether to list intermediate images. */
|
||||
is_intermediate?: boolean | null;
|
||||
/** @description The board id to filter by. Use 'none' to find images without a board. */
|
||||
board_id?: string | null;
|
||||
/** @description The order of sort */
|
||||
order_dir?: components["schemas"]["SQLiteDirection"];
|
||||
/** @description Whether to sort by starred images first */
|
||||
starred_first?: boolean;
|
||||
/** @description The term to search for */
|
||||
search_term?: string | null;
|
||||
};
|
||||
@@ -23754,56 +23725,7 @@ export interface operations {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ImageCollectionCounts"];
|
||||
};
|
||||
};
|
||||
/** @description Validation Error */
|
||||
422: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["HTTPValidationError"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
get_image_collection: {
|
||||
parameters: {
|
||||
query?: {
|
||||
/** @description The origin of images to list. */
|
||||
image_origin?: components["schemas"]["ResourceOrigin"] | null;
|
||||
/** @description The categories of image to include. */
|
||||
categories?: components["schemas"]["ImageCategory"][] | null;
|
||||
/** @description Whether to list intermediate images. */
|
||||
is_intermediate?: boolean | null;
|
||||
/** @description The board id to filter by. Use 'none' to find images without a board. */
|
||||
board_id?: string | null;
|
||||
/** @description The offset within the collection */
|
||||
offset?: number;
|
||||
/** @description The number of images to return */
|
||||
limit?: number;
|
||||
/** @description The order of sort */
|
||||
order_dir?: components["schemas"]["SQLiteDirection"];
|
||||
/** @description The term to search for */
|
||||
search_term?: string | null;
|
||||
};
|
||||
header?: never;
|
||||
path: {
|
||||
/** @description The collection to retrieve from */
|
||||
collection: "starred" | "unstarred";
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Successful Response */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["OffsetPaginatedResults_ImageDTO_"];
|
||||
"application/json": string[];
|
||||
};
|
||||
};
|
||||
/** @description Validation Error */
|
||||
|
||||
@@ -5,7 +5,7 @@ import { deepClone } from 'common/util/deepClone';
|
||||
import {
|
||||
selectAutoSwitch,
|
||||
selectGalleryView,
|
||||
selectListImagesQueryArgs,
|
||||
selectListImagesBaseQueryArgs,
|
||||
selectSelectedBoardId,
|
||||
} from 'features/gallery/store/gallerySelectors';
|
||||
import { boardIdSelected, galleryViewChanged, imageSelected } from 'features/gallery/store/gallerySlice';
|
||||
@@ -44,7 +44,7 @@ export const buildOnInvocationComplete = (getState: AppGetState, dispatch: AppDi
|
||||
const boardTotalAdditions: Record<string, number> = {};
|
||||
const boardTagIdsToInvalidate: Set<string> = new Set();
|
||||
const imageListTagIdsToInvalidate: Set<string> = new Set();
|
||||
const listImagesArg = selectListImagesQueryArgs(getState());
|
||||
const listImagesArg = selectListImagesBaseQueryArgs(getState());
|
||||
|
||||
for (const imageDTO of imageDTOs) {
|
||||
if (imageDTO.is_intermediate) {
|
||||
@@ -94,7 +94,7 @@ export const buildOnInvocationComplete = (getState: AppGetState, dispatch: AppDi
|
||||
type: 'ImageList' as const,
|
||||
id: imageListId,
|
||||
}));
|
||||
dispatch(imagesApi.util.invalidateTags([...boardTags, ...imageListTags]));
|
||||
dispatch(imagesApi.util.invalidateTags(['ImageNameList', ...boardTags, ...imageListTags]));
|
||||
|
||||
const autoSwitch = selectAutoSwitch(getState());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user