Ombi-app / Ombi

Want a Movie or TV Show on Plex/Emby/Jellyfin? Use Ombi!
http://ombi.io
GNU General Public License v2.0
3.71k stars 395 forks source link

IOS Apps - SQL improvements for better performance #5122

Open jr-air opened 4 months ago

jr-air commented 4 months ago

Summary

For the IOS Apps, on initial load they are slow to open especially on the "Popular TV" section. (MySql database in use)

1) Multiple queries are performed multiple times against services not enabled in OMBI. For example, If only Plex is enables, multiple queries are still performed against Emby and Jellyfin tables. Maybe an initial check on the enablement status can be done to suppress future queries?

2) For Popular TV, there are hundreds of "individual" queries performed, matching each Season and Episode pair. Ideally if possible, performing a bulk query loaded into an array that can then be processed in the app should allow for a significant performance boost?

Ombi Version

4.43.5

What platform(s) does this occur on?

Docker

What database are you using?

MySQL

Relevant log output

For item #2 above, this query is executed for each and every Season/Episode pair. For a TV series with 20 Seasons, and 20 Episodes per season, this equals 400 individual queries just for this one show... 

SELECT `p`.`Id`, `p`.`EpisodeNumber`, `p`.`GrandparentKey`, `p`.`Key`, `p`.`ParentKey`, `p`.`SeasonNumber`, `p`.`Title`, `p0`.`Id`, `p0`.`AddedAt`, `p0`.`Has4K`, `p0`.`ImdbId`, `p0`.`Key`, `p0`.`Quality`, `p0`.`ReleaseYear`, `p0`.`RequestId`, `p0`.`TheMovieDbId`, `p0`.`Title`, `p0`.`TvDbId`, `p0`.`Type`, `p0`.`Url`
FROM `PlexEpisode` AS `p`
LEFT JOIN `PlexServerContent` AS `p0` ON `p`.`GrandparentKey` = `p0`.`Key`
WHERE ((`p`.`EpisodeNumber` = 13) AND (`p`.`SeasonNumber` = 3)) AND (`p0`.`TheMovieDbId` = '2734')
LIMIT 1