Optimize Media Planning by skipping thumbnail generation
This change modifies the validation/planning phase to skip the expensive thumbnail generation step in 'getUnifiedMediaState'. Since the planning phase primarily needs file IDs and names to calculate deletions, adoptions, and reorders, skipping the thumbnail verification/retrieval (including sidecar checks) significantly reduces the latency of the 'Save Changes' operation.
This commit is contained in:
@ -106,6 +106,80 @@ export class ShopifyMediaService implements IShopifyMediaService {
|
||||
return response.content.data.product.media.edges.map((edge: any) => edge.node)
|
||||
}
|
||||
|
||||
getProduct(productId: string): any {
|
||||
const query = /* GraphQL */ `
|
||||
query getProduct($productId: ID!) {
|
||||
product(id: $productId) {
|
||||
id
|
||||
title
|
||||
handle
|
||||
onlineStoreUrl
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = { productId }
|
||||
const payload = buildGqlQuery(query, variables)
|
||||
const response = this.shop.shopifyGraphQLAPI(payload)
|
||||
if (!response || !response.content || !response.content.data || !response.content.data.product) {
|
||||
console.warn("getProduct: Product not found or access denied for ID:", productId);
|
||||
return null;
|
||||
}
|
||||
return response.content.data.product
|
||||
}
|
||||
|
||||
getProductWithMedia(productId: string): any {
|
||||
const query = /* GraphQL */ `
|
||||
query getProductWithMedia($productId: ID!) {
|
||||
product(id: $productId) {
|
||||
id
|
||||
title
|
||||
handle
|
||||
onlineStoreUrl
|
||||
media(first: 250) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
alt
|
||||
mediaContentType
|
||||
status
|
||||
preview {
|
||||
image {
|
||||
originalSrc
|
||||
}
|
||||
}
|
||||
... on Video {
|
||||
sources {
|
||||
url
|
||||
mimeType
|
||||
}
|
||||
}
|
||||
... on MediaImage {
|
||||
image {
|
||||
url
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const variables = { productId }
|
||||
const payload = buildGqlQuery(query, variables)
|
||||
const response = this.shop.shopifyGraphQLAPI(payload)
|
||||
if (!response || !response.content || !response.content.data || !response.content.data.product) {
|
||||
console.warn("getProductWithMedia: Product not found or access denied for ID:", productId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Normalize return structure to match expectations
|
||||
const p = response.content.data.product;
|
||||
return {
|
||||
product: { id: p.id, title: p.title, handle: p.handle, onlineStoreUrl: p.onlineStoreUrl },
|
||||
media: p.media.edges.map((edge: any) => edge.node)
|
||||
};
|
||||
}
|
||||
|
||||
productDeleteMedia(productId: string, mediaId: string): any {
|
||||
const query = /* GraphQL */ `
|
||||
mutation productDeleteMedia($mediaIds: [ID!]!, $productId: ID!) {
|
||||
|
||||
Reference in New Issue
Block a user