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

[4.x]: Change in ElementQuery::count effecting EVENT_BEFORE_PREPARE events #15001

Closed
myleshyson opened this issue May 15, 2024 · 10 comments
Closed
Assignees

Comments

@myleshyson
Copy link
Contributor

myleshyson commented May 15, 2024

What happened?

Description

We noticed that after updating to Craft 4.9, one of our queries wasn't running properly. The logic for this particular query depends on the EntryQuery::EVENT_BEFORE_PREPARE event. In particular, in depended on the orderBy property to be null for for count queries to run properly.

Now however, because of this change, the orderBy property is not being nulled like it was before with yiii\db\Query::queryScaler method.

I'm not sure if this was on purpose? Either way would it be possible to either:
a) keep the queryScaler logic from yiii\db\Query::queryScaler for scalar queries (count, min, max, etc) so that things run like they did before the change OR
b) add a property to ElementQuery, something like queryMethod, so that events can add that logic back if the query is a scalar query?

Craft CMS version

Craft 4.9.0

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

@yannkost
Copy link

I have also noticed that the .count() function does not return the right value for some queries.

{% set searchQuery = craft.entries({ type: availableEntryTypes}).search(query).orderBy('score').limit(5) %}

This sample code does return the limit of 5 and not the number of the entries.

@yannkost
Copy link

yannkost commented May 16, 2024

Just checked and without the orderBy('score') the function call returns the correct number.

@i-just
Copy link
Contributor

i-just commented May 17, 2024

@myleshyson, in your case, the EntryQuery::EVENT_BEFORE_PREPARE used to rely on the $event->sender->orderBy returning null, but since 4.9, it’s returning an empty string.

@yannkost, in your case, it’s the combination of search, limit and orderBy('score').

I raised a draft PR, and we’ll discuss this internally.

@brandonkelly
Copy link
Member

Craft 4.9.5 and 5.1.5 are out with a fix that covers both of these issues. Thanks for reporting!

@lindseydiloreto
Copy link
Contributor

This fix seems to have broken proximity searches for both the Google Maps and Maps plugins.

I've been digging around through the plugins and Craft itself, but can't figure out exactly:

  • What benefit did these changes provide?
  • How should our proximity search plugins be adjusted accordingly?

Do you have any recommendations?

@brandonkelly
Copy link
Member

@lindseydiloreto Can you write into [email protected] with Composer files and a database backup for a site that demonstrates the issue?

@lindseydiloreto
Copy link
Contributor

@brandonkelly Certainly, I'll send it over. Thanks!

@amici-infotech
Copy link

We are using Maps plugin in multiple projects and it seems to be broken after both craft 4 and 5 upgrades.

@brandonkelly
Copy link
Member

Craft 4.10.2 and 5.2.2 are out with a fix for Google Maps and Maps. Thanks for reporting @lindseydiloreto!

@lindseydiloreto
Copy link
Contributor

Sweet, no problem! Thanks for getting it sorted out so quickly! 🍺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants