Problem/Motivation
#2664388: Add index on {file_managed_revisions}.uri and {file_managed}.vid adds an index for the slow query from here.
However looking at the query, I'm not sure that's the only problem:
1. First I thought it should use db_query_range() instead of just relying on getting the last result.
2. Then I realised it always grabs the latest selection based on version ID, but if a site is using a workflow module like workbench or CPS, then the latest revision may not be the current one. I think it should join on {file_managed} on fid then figure out the vid from there. Then it could also skip the ORDER BY entirely - will always get a single row.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
catchHere's a patch. Gets the query down from hundreds of milliseconds down to 1ms for me.
Comment #3
catchComment #5
matthijsPatch applied and committed, thanks!
Comment #6
David_Rothstein commentedThis patch actually seems to be causing problems with CPS - when you have CPS enabled the vid recorded in the {manualcrop} table is not necessarily the same one that's in the {file_managed} table, so crops are not found correctly.
This also could cause bigger problems with a site that is using Manual Crop already and then turns on File Entity Revisions later. In that case Manual Crop will have stored "0" for the vid for all existing crops (see manualcrop_save_crop_data()), but I believe File Entity Revisions will assign new revision IDs to the existing files after it's enabled, and thus there will be a mismatch and all the existing crops won't be found. (Haven't tested that though.)
It may be a good idea to roll this back for now?
Comment #7
catchHere's an alternative patch that just changes the sort on vid to be on {file_managed_revisions} instead of {manualcrop} - that fixes the temp table/filesort but doesn't change the actual logic.
This doesn't fix the original problem I identified with CPS-compatibility, but it also doesn't make it worse like #2 apparently does.
Bumping to major because at least the first patch should be reverted - the second patch is based on HEAD prior to that going in so should apply once the revert has happened.
Comment #8
catchComment #10
David_Rothstein commentedI don't know if that's possible to fix without a major rewrite - see my earlier analysis at #2582829: Support for file entity revisions is broken (the wrong manual crop settings are used unless different revisions have different file URIs).
Comment #11
catch@David thanks for the link. Yes I've not been able to come up with any ideas to fully support forward-revisions with manualcrop at all yet. Which means assuming #7 does what it's supposed to do, that's likely as far as we can get without a lot of work.
Comment #12
David_Rothstein commentedThere were a couple more problems with the above patch:
$query->range(0, 1)call meant the function was returning the wrong set of results (only returned data for one style name rather than all of them).Here's a new patch that fixes the above. I've done some testing in various scenarios and it seems to work while retaining the performance improvement from the previous patch.
One situation it probably fails in is the edge case where you turn off the file_entity_revisions module after using it for a while. But in that case I don't think the current module code works then either.
Comment #13
David_Rothstein commentedNo longer needs to be major, since the earlier patch was reverted.
Comment #15
matthijsThanks for the patch guys!