Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate transforms by the specified index from Assets Controller #15402

Closed
wants to merge 1 commit into from

Conversation

adrum
Copy link

@adrum adrum commented Jul 23, 2024

Description

TL;DR: When passing a transform index ID to /actions/assets/generate-transforms, the action should generate that exact index.

Full Story: We launched a site running 4.10.4 and somehow ended up with duplicate rows in our imagetransformindex table. Our template eager loaded transforms, and it yields the second row from the table (id: 21) for a particular transform. When the Assets Controller went to generate the transform by ID, it actually queries the imagetransformindex table based on the attributes of the transform, which would yield the first row (id: 20) and not the actual row requested (id: 21). This would yield an ever-growing queue of image transformations that would never flip the fileExists to 1 on id 21.

I recognize this solution deals with symptoms and not the root problem, but at least it prevents the queue from infinitely pushing image transforms jobs. I believe this fix is also applicable for 5.x.

We did have multiple processes in our supervisor config, so that was probably the root cause of the duplicate rows. I used these queries to diagnose and clean up the table:

SELECT 
  assetId,
  format,
  transformString, 
  COUNT(*) as duplicate_count
FROM 
  craft_imagetransformindex
GROUP BY 
  assetId, format, transformString
HAVING 
  COUNT(*) > 1;


DELETE FROM craft_imagetransformindex
WHERE id NOT IN (
  SELECT id FROM (
    SELECT MIN(id) as id
    FROM craft_imagetransformindex
    GROUP BY assetId, format, transformString
  ) as subquery
);

Related issues

#12453

@i-just
Copy link
Contributor

i-just commented Aug 5, 2024

Hi @adrum, thanks for this!
I tweaked your idea a bit to avoid changing the ImageTransformerInterface->getTransformUrl() signature, so I’m closing this one in favour of #15477.

@i-just i-just closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants