It’s gotten real slow for us when searching for a specific user - In this case it is taking 2019 seconds - over a half hour(!) (the web request is timed out by the time that finishes)
Here’s the slightly redacted log entry from the MySQL Slow Query Log:
# Time: 210616 23:33:12
# Query_time: 2019.308077 Lock_time: 0.000226 Rows_sent: 0 Rows_examined: 122481553
SELECT DISTINCT u.*,
COALESCE(ugl.setting_value, ugpl.setting_value) AS user_given,
CASE WHEN ugl.setting_value <> '' THEN ufl.setting_value ELSE ufpl.setting_value END AS user_family
FROM users AS u
LEFT JOIN user_settings us ON (us.user_id = u.user_id AND us.setting_name = 'affiliation')
LEFT JOIN user_interests ui ON (u.user_id = ui.user_id)
LEFT JOIN controlled_vocab_entry_settings cves ON (ui.controlled_vocab_entry_id = cves.controlled_vocab_entry_id)
LEFT JOIN user_user_groups uug ON (uug.user_id = u.user_id)
LEFT JOIN user_groups ug ON (ug.user_group_id = uug.user_group_id)
LEFT JOIN user_settings ugl ON (u.user_id = ugl.user_id AND ugl.setting_name = 'givenName' AND ugl.locale = 'en_US')
LEFT JOIN user_settings ugpl ON (u.user_id = ugpl.user_id AND ugpl.setting_name = 'givenName' AND ugpl.locale = 'en_US')
LEFT JOIN user_settings ufl ON (u.user_id = ufl.user_id AND ufl.setting_name = 'familyName' AND ufl.locale = 'en_US')
LEFT JOIN user_settings ufpl ON (u.user_id = ufpl.user_id AND ufpl.setting_name = 'familyName' AND ufpl.locale = 'en_US')
LEFT JOIN user_settings usgs ON (usgs.user_id = u.user_id AND usgs.setting_name = 'givenName')
LEFT JOIN user_settings usfs ON (usfs.user_id = u.user_id AND usfs.setting_name = 'familyName')
WHERE 1=1 AND ( ( LOWER(CONCAT(COALESCE(usgs.setting_value,''),COALESCE(usfs.setting_value,''),u.email,COALESCE(us.setting_value,''))) LIKE '%usernamehere%' OR LOWER(cves.setting_value) LIKE 'usernamehere%' ) ) ORDER BY user_family, user_given LIMIT 25 OFFSET 0;
I’ve done a cursory check for indexes and they seem to be there as suggested. We have 2530 users. Running 3.3.0.6.
We are having the same problem. but in the DB we have too many spam users from OJS2 version like around ~700k (yes). in the whole site.
There are 53 journals hosted on the site and we getting ~5mins to pre-load the user page or in peak hours it just never ends loading the user page.
Anyone know how to skip the pre-loading just let the journal managers to perform search when they need? sometimes they are justing searching inside a small group of users like section eidtors.
This is the query we stuck at the most:
select u.*, COALESCE(ugl.setting_value, ugpl.setting_value) AS user_given,
CASE WHEN ugl.setting_value <> ‘’ THEN ufl.setting_value ELSE ufpl.setting_value END AS user_family, MAX(ra.date_assigned) as last_assigned,
(SELECT SUM(CASE WHEN ra.date_completed IS NULL AND ra.declined <> 1 THEN 1 ELSE 0 END) FROM review_assignments AS ra WHERE u.user_id = ra.reviewer_id) as incomplete_count,
(SELECT SUM(CASE WHEN ra.date_completed IS NOT NULL AND ra.declined <> 1 THEN 1 ELSE 0 END) FROM review_assignments AS ra WHERE u.user_id = ra.reviewer_id) as complete_count,
(SELECT SUM(CASE WHEN ra.declined = 1 THEN 1 ELSE 0 END) FROM review_assignments AS ra WHERE u.user_id = ra.reviewer_id) as declined_count,
(SELECT SUM(CASE WHEN ra.cancelled = 1 THEN 1 ELSE 0 END) FROM review_assignments AS ra WHERE u.user_id = ra.reviewer_id) as cancelled_count,
AVG(DATEDIFF(ra.date_completed, ra.date_notified)) as average_time, (SELECT AVG(ra.quality) FROM review_assignments AS ra
WHERE u.user_id = ra.reviewer_id AND ra.quality IS NOT NULL) as reviewer_rating from users as u
left join user_user_groups as uug on uug.user_id = u.user_id
left join user_groups as ug on ug.user_group_id = uug.user_group_id
left join user_settings as ugl on ugl.user_id = u.user_id and ugl.setting_name = ‘givenName’ and ugl.locale = ‘en_US’
left join user_settings as ugpl on ugpl.user_id = u.user_id and ugpl.setting_name = ‘givenName’ and ugpl.locale = ‘en_US’
left join user_settings as ufl on ufl.user_id = u.user_id and ufl.setting_name = ‘familyName’ and ufl.locale = ‘en_US’
left join user_settings as ufpl on ufpl.user_id = u.user_id and ufpl.setting_name = ‘familyName’ and ufpl.locale = ‘en_US’
left join user_group_stage as ugs on uug.user_group_id = ugs.user_group_id left join user_settings as us on u.user_id = us.user_id
left join user_interests as ui on u.user_id = ui.user_id
left join controlled_vocab_entry_settings as cves on ui.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
left join review_assignments as ra on u.user_id = ra.reviewer_id where ug.context_id = 2 and ug.role_id in (4096) and u.disabled = 0 and ugs.stage_id = 3
and (lower(u.username) LIKE ‘%or%’ or lower(u.email) LIKE ‘%or%’
or (us.setting_name = ‘givenName’ and lower(us.setting_value) LIKE ‘%or%’)
or (us.setting_name = ‘familyName’ and lower(us.setting_value) LIKE ‘%or%’)
or (us.setting_name = ‘affiliation’ and lower(us.setting_value) LIKE ‘%or%’)
or (us.setting_name = ‘biography’ and lower(us.setting_value) LIKE ‘%or%’)
or (us.setting_name = ‘orcid’ and lower(us.setting_value) LIKE ‘%or%’)
or lower(cves.setting_value) LIKE ‘%or%’)
group by u.user_id, user_given, user_family order by u.user_id desc LIMIT 30 OFFSET 0
Chiming in, we are on version 3.3.0-17 and are having the same issue. Maybe we are seeing a different problem from the one solved in issue #6991. We are running a multi journal installation with 2.848 entries in “users” and ~36.000 in “user_settings”. The query executed by clicking on “Users & roles” is the following and takes ~90s to resolve in the backend (even if it is run in the DB directly):
SELECT u.*, (
SELECT us.setting_value
FROM user_settings AS us
WHERE
us.user_id = u.user_id
AND us.setting_name = 'givenName'
AND us.locale IN ('en_US', 'de_DE')
-- First non-null/empty values, then give preference to the current locale
ORDER BY
COALESCE(us.setting_value, '') = '', us.locale <> 'en_US'
LIMIT 1
) AS user_given, (
SELECT us.setting_value
FROM user_settings AS us
WHERE
us.user_id = u.user_id
AND us.setting_name = 'familyName'
AND us.locale IN ('en_US', 'de_DE')
-- First non-null/empty values, then give preference to the current locale
ORDER BY
COALESCE(us.setting_value, '') = '', us.locale <> 'en_US'
LIMIT 1
) AS user_family
FROM users AS u
WHERE 1 = 1 AND EXISTS (
SELECT 0
FROM user_user_groups uug
INNER JOIN user_groups ug
ON ug.user_group_id = uug.user_group_id
WHERE
uug.user_id = u.user_id
AND ug.context_id = 19
) ORDER BY user_family, user_given LIMIT 25 OFFSET 0
Does anyone have any idea what’s causing the slowdown here?
Today I’ve updated the PRs, so I think they will be available into the next release, I’ve spread the improvement to everywhere that had the same problem, so a couple of other places should get a performance bump as well.
** If anyone who’s having the issue is able to apply the PRs and check if it solves the problem, I’d be grateful.**