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

FIX Opt-in performance fix for many consecutive lookups using isLocalisedInStage #468

Merged

Conversation

ScopeyNZ
Copy link
Collaborator

@ScopeyNZ ScopeyNZ commented Sep 21, 2018

This PR adds a static method to pre-populate a cache of object IDs that exist in the given locale. This can be opted into by calling this method from appropriate user-code (or user-code extension) or alternatively by providing a list of classes that should be pre-populated (done when the first call of isLocalisedInStage is performed for that class).

Ideally I wouldn't have this config option but it is currently quite difficult to find a location to prepopulate this cache when running the SiteTree, although I'm open to suggestions here and more than happy to remove the configuration part of this PR.

Fixes #467

@sminnee
Copy link

sminnee commented Sep 21, 2018

Let's implement silverstripe/silverstripe-framework#8391 and then refactor this PR to provide a onPrepopulateTreeDataCache() implementation on the FluentSiteTreeExtension.

@sminnee
Copy link

sminnee commented Sep 21, 2018

This should probably be committed to master / 4.2.x-dev

@sminnee
Copy link

sminnee commented Sep 21, 2018

A patch for this is here https://gist.github.com/bec52b2d0f50a42f44a0aea2a05bc2af

If you can give me commit rights to the creative-commoners repo I'll push it to this branch

@robbieaverill
Copy link
Contributor

@sminnee done

return;
}

// This functionality hasn't been implemented; it's not actually used right now, so assumeYAGNI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clarify this comment a bit? The end doesn't make sense to me

Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just that comment to tidy up

@ScopeyNZ ScopeyNZ force-pushed the pulls/4.1/affluent-caches branch from 01b2e3a to c724a85 Compare September 25, 2018 02:03
@ScopeyNZ
Copy link
Collaborator Author

I have updated the comment. I just translated the acronym 🙂

@robbieaverill
Copy link
Contributor

Ok so is this PR dependant on silverstripe/silverstripe-framework#8380? If so, we'll need to prepare a new minor release which has a 4.3 minimum in core, since that PR was merged into 4.3.x-dev

@ScopeyNZ
Copy link
Collaborator Author

Right. I can rebase this onto 4 in the morning...

Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be rebased onto 4 and composer constraints for core updated to 4.3+

@sminnee
Copy link

sminnee commented Sep 25, 2018

@robbieaverill @ScopeyNZ this doesn't require 4.3+, but it's a no-op until 4.3 is installed. I don't think the constraint change is required then?

@robbieaverill
Copy link
Contributor

OK sweet

@robbieaverill
Copy link
Contributor

In that case there's no rebase required. It'd be cool to get Travis going before merge (I've pinged Damian), but if they pass locally then go for it

@sminnee
Copy link

sminnee commented Sep 25, 2018

I wonder if @tractorcow wants to invite some commoners to help till the farm?

src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
@maxime-rainville
Copy link

Probably need to write some unit test for this as well.

src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
src/Extension/FluentVersionedExtension.php Outdated Show resolved Hide resolved
@ScopeyNZ ScopeyNZ force-pushed the pulls/4.1/affluent-caches branch from 5e91803 to 46c53a2 Compare September 26, 2018 05:21
@ScopeyNZ ScopeyNZ force-pushed the pulls/4.1/affluent-caches branch from 46c53a2 to 77a3a6f Compare September 26, 2018 05:22
@robbieaverill robbieaverill self-assigned this Sep 27, 2018
@@ -304,29 +332,99 @@ protected function isLocalisedInStage($stage, $locale = null)
$table .= self::SUFFIX_LIVE;
}

if (isset(static::$idsInLocaleCache[$locale][$table])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this isset check should include the owner's ID like the line below

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I didn't is because we know all the IDs that exist in the locale for that table - the absence of an ID implies it's not there. So items that aren't in that stage/locale will skip this cache if you isset check the ID too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked this. Omitting owner ID drops another 105 queries... I'll PR to remove it again and we can continue discussion there 🙂

@robbieaverill
Copy link
Contributor

I've done a little bit of a refactor in order to unit test this easily, and have pushed some new tests. LGTM. I think @tractorcow's feedback has been addressed

@robbieaverill robbieaverill dismissed tractorcow’s stale review September 27, 2018 11:13

I think these comments have been addressed

@robbieaverill
Copy link
Contributor

We don't have Travis set up on this org yet (cc @tractorcow)

@tractorcow if you don't think we've correctly addressed your comments feel free to ping us and we'll look more into it =)

@robbieaverill robbieaverill merged commit 8b5cb0b into tractorcow-farm:4.1 Sep 27, 2018
@robbieaverill robbieaverill deleted the pulls/4.1/affluent-caches branch September 27, 2018 11:14
@robbieaverill robbieaverill removed their assignment Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants