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

[STU-58] Indexing jobs sent to queue runner only run from primary site #266

Closed
benlobach opened this issue Aug 15, 2023 · 8 comments
Closed
Assignees
Labels
🕷 bug linear Created by Linear-GitHub Sync

Comments

@benlobach
Copy link

benlobach commented Aug 15, 2023

Hello!

We've encountered an bug when using multi-site in CraftCMS 4 where entries enter the queue when they are saved, but they don't make it into Algolia. Disabling the queue and/or pushing the sync through the utilities works perfectly. Digging into the jobs code, we found an element query that doesn't include all sites, and that often keeps other sites from indexing when using the queue runner.

https://github.com/studioespresso/craft-scout/blob/16f13633b62fe1f11f558af4bc20f2841756c209/src/jobs/IndexElement.php#L18C7-L18C7

Changing this line as follows appears to correct the issue:
$element = Craft::$app->getElements()->getElementById($this->id, NULL, "*"); // Parameters: ID, Type, and Site ID

https://docs.craftcms.com/api/v4/craft-services-elements.html#method-getelementbyid

Thanks for taking a look, we truly appreciate the work you're putting into this plugin!

CraftCMS Version: 4.4.17
Scout Version: 3.1.2

STU-58

@benlobach benlobach changed the title Indexing Jobs Sent to Queue Runner Only Run from Primary Site Indexing jobs sent to queue runner only run from primary site Aug 15, 2023
@janhenckens
Copy link
Member

Hey @benlobach, thanks for reporting this. A colleague of mine reported a similar issue in #270 (where the indexing job doesn't fire when an item is save from a non-primary site).

Changing the getElementById code doesn't seem to fix it on my end - but I don't specify any site in my Scout configuration. Could you share the criteria you have in scout.php? Thanks!

@benlobach
Copy link
Author

Hey @janhenckens, thanks for looking into it! We are specifying the site in both locations, and it appears to be working with this configuration along with the getElementbyId change.

->criteria(function (\craft\elements\db\EntryQuery $query) { return $query->siteId(4)->type(['articles']); })

@janhenckens
Copy link
Member

hey @benlobach , a fix for this is out in 3.1.3. Can you give that a try? Thanks!

@benlobach
Copy link
Author

Thank you, @janhenckens!

@mathg
Copy link

mathg commented Oct 13, 2023

On my end I still have this issue. When saving an Entry not in a primary site, the after save hook for indexing gets triggered but it only indexes the Entry from the primary site. The relations are saved correctly in all sites.

The Refresh buttons index them properly.

Edit: If I change the 'queue' param to false in config/scout.php it works properly. It looks like the queue is ran from the primary site and doesn't load the element properly when indexing the element.

@janhenckens
Copy link
Member

@mathg Thanks for adding that, I'll try to reproduce and get back to you over the weekend!

@janhenckens janhenckens added the linear Created by Linear-GitHub Sync label Oct 18, 2023
@janhenckens janhenckens changed the title Indexing jobs sent to queue runner only run from primary site [STU-58] Indexing jobs sent to queue runner only run from primary site Oct 18, 2023
janhenckens added a commit that referenced this issue Oct 23, 2023
@janhenckens
Copy link
Member

Hey all, I just released an update that includes a fix for this. Could you update and give it a try? Thanks!

@mathg
Copy link

mathg commented Oct 24, 2023

@janhenckens it works properly on my end now, thanks!

qrazi pushed a commit to qrazi/craft-scout that referenced this issue Dec 12, 2023
janhenckens added a commit that referenced this issue Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🕷 bug linear Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

3 participants