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

catch created an issue. See original summary.

catch’s picture

Status: Active » Needs review
StatusFileSize
new2.97 KB

Here's a patch. Gets the query down from hundreds of milliseconds down to 1ms for me.

catch’s picture

Title: manual_crop_load_crop_selection() query looks incorrect » manual_crop_load_crop_selection() causes a temp table/filesort and incompatible with forward-revision modules

  • Matthijs committed 064adb5 on
    Issue #2664528: Updated load query to use INNER joins.
    
  • Matthijs committed 70ea8d2 on authored by catch
    Issue #2664528 by catch: Fixed peformance of the crop selection load...
matthijs’s picture

Status: Needs review » Fixed

Patch applied and committed, thanks!

David_Rothstein’s picture

Status: Fixed » Needs work

This 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?

catch’s picture

Category: Task » Bug report
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new2.98 KB

Here'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.

catch’s picture

Title: manual_crop_load_crop_selection() causes a temp table/filesort and incompatible with forward-revision modules » manual_crop_load_crop_selection() causes a temp table/filesort

David_Rothstein’s picture

This doesn't fix the original problem I identified with CPS-compatibility

I 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).

catch’s picture

@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.

David_Rothstein’s picture

StatusFileSize
new3.55 KB
new2.16 KB

There were a couple more problems with the above patch:

  1. The function wasn't returning the style_name column when it needed to.
  2. In the case where no style name was passed in to the function, the $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.

David_Rothstein’s picture

Priority: Major » Normal

No longer needs to be major, since the earlier patch was reverted.

  • Matthijs committed 2688618 on 7.x-1.x authored by David_Rothstein
    Issue #2664528 by catch, David_Rothstein: Fixed...
  • Matthijs committed f999e34 on 7.x-1.x
    Issue #2664528: Added some extra whitespace in the changes from previous...
matthijs’s picture

Status: Needs review » Fixed

Thanks for the patch guys!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.