-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Sync only on Entry Events #205
Comments
Hey @toyflish, good point, I can see how that would create an issue. Lines 142 to 146 in e7709b6
To the settings/config file with these as default. That way you could change them out as needed. Seems like a pretty safe change. |
@toyflish - We're seeing the same thing, but it seems it only began after recently updating to Craft 3.7.x. Is that your experience too? @janhenckens - We're eager for a solution too. If necessary, I believe we can resort to console sync on a cron, but something that allows us to keep content-based syncing from the CP would be phenomenal. |
@sjcallender Hmm, weird that it would only show up after 3.7.x, the plugin certainly hasn't changed since then and Craft's internal events we're listening for have always been Element based, triggering for entries as well as matrix blocks. I'll try to work out the above solution and get back to you asap! |
@sjcallender can you make sure you're on the latest (craftcms/cms@3.7.11), we just fixed an index regression issue that affected save performance. |
@timkelty - Thanks. We're on 3.7.11 after Brad and Oli noted it in a support email. It didn't help in our case. Only disabling Scout helps. |
@sjcallender 👍 Just talked it over with @janhenckens and I think he has a plan to address. |
@toyflish @sjcallender Just released 2.4.2 which includes a new Kudos to @timkelty for the back and forth :) |
Sweet. Thanks @janhenckens. My main back-end dev is on vacation and I'm not a PHP/plugin dev, so what file would that snippet from the docs go into? Into a custom module? |
Yes, in a module. You'd have to add some code to check the element in question too, just adding it like the example will result in nothing ever being searchable again so you don't want that :) |
thanks @janhenckens, |
@janhenckens - I'm a bit confused on how to implement the event too. We have a homepage entry (id=2) that, currently, when saved, triggers a sync for all its related product entries. We want to stop syncing these products when the homepage entry is saved. We added the following to our module. Event::on(
SearchableBehavior::class,
SearchableBehavior::EVENT_SHOULD_BE_SEARCHABLE,
function (ShouldBeSearchableEvent $event) {
if ($event->element->getId() === 2) {
$event->shouldBeSearchable = false;
}
}
); The above still syncs the products. However, if change the conditional to the following, we're no longer syncing. if ($event->element->getId() !== 2) {
$event->shouldBeSearchable = false;
} As you can guess, this second conditional blocks all entries from being synced even when they are saved directly. How should we be setting up our logic to prevent syncing of related entries only? |
Got it working using the slug. // prevent syncing related entries
Event::on(
SearchableBehavior::class,
SearchableBehavior::EVENT_SHOULD_BE_SEARCHABLE,
function (ShouldBeSearchableEvent $event) {
// after saving homepage entry
if ($event->element->slug === 'homepage') {
$event->shouldBeSearchable = false;
}
}
); |
Hmm, fair point @toyflish. Sounds like you want to disable the updating of related events then? |
@janhenckens - That's what we're trying to do too. In my code above, I'm realizing it works only if I'm not "applying" a draft, provisional or regular. Some guidance would be appreciated. |
@sjcallender @toyflish Sounds like not having related entries automatically indexed would fix it for you both? I had intended the event to give you the option to check wether or not the element is an entry and not for example a matrix block, like it @toyflish's original question. I'll have a think on how to check for related entries. |
@janhenckens Weighing in to also request disabling automatic indexing of related entries. We, too, have a very large database and would prefer to just push the entry being saved into Algolia for performance reasons. Related content will be pushed as those entries are saved. |
@janhenckens I think so, yes. We don't have any scenarios where we want to sync the related elements when syncing any one particular element. Related content would be indexed within that element's document, or indexed independently when it was saved. Thanks! |
Just released 2.5.0 which has this included. You can now set Could you give this a try and report back if this improves things for you @heymarkreeves @sjcallender @toyflish? I'll leave this issue open for a bit, feel free to jump in with your thoughts! |
@janhenckens It works great! Thanks for this. |
I got a Section with huge Entries with a matrix with hundreds of fields in 4 languages. I have another Section Routines that are indexed in algolia.
With scout-plugin enabled when I hit save on an entry in the huge-entry-section, the request takes 2minutes to resolve with hundreds of sql selects going on.
When I disable scout-plugin, the time to save huge entries goes down to 5 seconds.
I guess this is because scout listens to Elements::EVENT_AFTER_SAVE_ELEMENT on every field on the huge entry and ramps up hundreds of sql-selects to check if they fit the indexing-criteria.
How can I remove this behaviour and just have scout to action on Entry::EVENT_AFTER_SAVE so that it just adds one more query for criteria-matching to saving an entry instead of hundreds?
this is my scout.php creating four indices for four languages:
The text was updated successfully, but these errors were encountered: