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

Closes #937 Optimise sql query for image counting and statistics #957

Merged
merged 13 commits into from
Jan 27, 2025

Conversation

Khadreal
Copy link
Contributor

Description

Optimise SQL query for image counting.

Fixes #937

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

Check #937

Technical description

Documentation

Modify existing query to be faster and rewrite imagify_has_attachments_without_required_metadata sql to be more optimised.
Changed from using left join to Exists

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

If some mandatory items are not relevant, explain why in this section.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

Copy link

codacy-production bot commented Jan 20, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 2ec0c9f1 0.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2ec0c9f) Report Missing Report Missing Report Missing
Head commit (9d1f8d3) 13373 29 0.22%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#957) 75 0 0.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Khadreal Khadreal marked this pull request as ready for review January 20, 2025 13:39
@Khadreal Khadreal self-assigned this Jan 20, 2025
@Khadreal Khadreal requested a review from a team January 20, 2025 14:15
@MathieuLamiot
Copy link
Contributor

@Khadreal Do you think adding tests could be beneficial on those queries?
It could help ensure we have the same results before and after the changes.

@Khadreal
Copy link
Contributor Author

@Khadreal Do you think adding tests could be beneficial on those queries?
It could help ensure we have the same results before and after the changes.

Yes, Will try to add a test to it.

@Mai-Saad
Copy link

@Khadreal Thanks for the PR. here is a test sample result of PR Vs Production
1- improvement in this query imagify_has_attachments_without_required_metadata()
2- increase in this query imagify_count_optimized_attachments()
3- some queries added on PR with certain actions and not there on production (the grey cells)
Screenshot from 2025-01-21 13-55-47
What do you think?

@Khadreal
Copy link
Contributor Author

@Mai-Saad will fine tune the queries that increased, the queries that are added on the PR and not on production could be as a result of filter here which is disable by default. Are you certain that the filter is not enable during your test ?

@Mai-Saad
Copy link

Mai-Saad commented Jan 21, 2025

The filter imagify_display_library_stats is enabled on both production and PR
https://bmdo-my.sharepoint.com/:x:/r/personal/mai_saad_group_one/Documents/imagify%20measurements.xlsx?d=w83baa867dabe49c1abbae2280ab91751&csf=1&web=1&e=4nNfQX

Copy link

codacy-production bot commented Jan 22, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 2ec0c9f1 5.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2ec0c9f) Report Missing Report Missing Report Missing
Head commit (4485594) 13954 48 0.34%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#957) 100 5 5.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@Mai-Saad
Copy link

Working as expected.
Note:

  • some test cases need maintenance
  • already on trunk, if we deleted imagify_user_cache transient, it will be recreated and API request will be sent while being on transient page , refreshing won't send any requests
    testrail-report-685.pdf

@Mai-Saad Mai-Saad added this pull request to the merge queue Jan 27, 2025
Merged via the queue into develop with commit 384a28c Jan 27, 2025
9 of 11 checks passed
@Mai-Saad Mai-Saad deleted the enhancement/937-optimise-sql-queries branch January 27, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize SQL Queries for image counting and statistics
5 participants