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

Improve sql query performance by removing unused payload #2195

Merged
merged 1 commit into from
Apr 16, 2023

Conversation

starze
Copy link
Contributor

@starze starze commented Apr 12, 2023

Summary

This is a quick-fix to Improve a specific SQL query from 22-37s to <1s when refreshing news items.

Some details how I got to that solution:

Activate slow-queries

SET GLOBAL slow_query_log=1;

Revealed slow-query:

SELECT `items`.* FROM `oc_news_items` `items` INNER JOIN `oc_news_feeds` `feeds` ON items.feed_id = feeds.id WHERE feeds.user_id = 'xxx' ORDER BY `items`.`id` DESC LIMIT 1;
// 1 row in set (37.087 sec)

SELECT count(*) from oc_news_items;
// 156391

After reducing payload (items.* --> items.id) the query is way faster:

SELECT `items`.`id` FROM `oc_news_items` `items` INNER JOIN `oc_news_feeds` `feeds` ON items.feed_id = feeds.id WHERE feeds.user_id = 'xxx' ORDER BY `items`.`id` DESC LIMIT 1;
// 1 row in set (0.042 sec)

newest() now only returns an entity with an id and not a complete news item anymore. All usages that I found are only using the id so i guess we are fine at the moment but maybe we need to change the function name or at least the return description.

This seams to be the first function that only returns parts of an item so I was unsure how to handle it. Feel free to change PR to fit your needs :-)

See also #1322 (comment)
And maybe another valid approach is still #1322 (comment) (not tested)

Checklist

@SMillerDev
Copy link
Contributor

Could you also update the test and changelog to reflect this?

@starze
Copy link
Contributor Author

starze commented Apr 13, 2023

If my approach is to your liking, I will try to dig into it.

@SMillerDev
Copy link
Contributor

If it works I like it 😅

@Grotax
Copy link
Member

Grotax commented Apr 16, 2023

Thanks for your contribution @starze

@Grotax Grotax merged commit 2d4cb5e into nextcloud:master Apr 16, 2023
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.

3 participants