https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38646 Bug ID: 38646 Summary: C4::Languages::getLanguages is very unreasonably slow (100+ ms) Change sponsored?: --- Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Searching Assignee: koha-bugs@lists.koha-community.org Reporter: schodkowy.omegi-0r@icloud.com QA Contact: testopia@bugs.koha-community.org My profiling with NYTProf has found that the call to C4::Languages::getLanguages is unreasonably slow, taking over 100 ms (and that's just on a single call of it apparently!!!). Indeed, the way it's coded, it'd run over 540 SQL queries for no good reason, slowing the already slow catalog search page loading further down. This patch is gonna replace the inefficient and complicated function logic with proper SQL statement that joins the relevant functions. It also fixes the bug where user's native language would be displayed with native language in the parenthesis as well, such as "Polski (Polski)" instead of just "Polski". The whole query is pretty fast and it gets cached by MySQL server, meaning it's runtime is measured in microseconds instead of hundreds of miliseconds, making it easily a 1000x+ improvement. The nested CASE statements are a bit verbose, but not too bad, I figured it might be better to do that rather than select all the vars as temporary columns and later remove them or re-create the new object to return. Instead, no temporary variables that one has to remove will linger... Please note that I didn't test the actual code since I don't have a working ktd installation by hand, but I did test the SQL statement thoroughly. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.