I just updated a site and now I’m not able to access /my/preferences/account. I get
Server Error while trying to load /user-badges/jayp.json Error code: 504 Gateway Time-out
I tried safe mode, and removed the only non-standard plugin (retort).
Though other users do seem to be able to access their preferences. Many are complaining about group-based theme modifications not working, so it seems that there might be some problem with groups.
Other pages seem to load fine, however. I don’t see anything in the logs in the web interface and don’t see it in the rails logs either.
I cannot replicate this here or on another site that I upgraded today.
EDIT: My current guess is that the problem has to do with some custom badge. There are many of them, but they aren’t SQL badges, and now that I see that, the badge hypothesis doesn’t make much sense.
method=GET path=/user-badges/jayp.json format=json controller=UserBadgesController action=username status=200 duration=5684.38 view=0.10 db=5577.50 params=_=1533766004403&username=jayp database=default db_calls=111 redis=0.73 redis_calls=6 ip=22.214.171.124 username=jayp
Now that’s a lot of queries …
Reproduced and checked locally,
UserSerializer is making tons of SQL queries on the fly when serializing
UserSerializer is an overkill for the badges page, and
BasicUserSerializer should do?
class DetailedUserBadgeSerializer < BasicUserBadgeSerializer
- has_one :granted_by
+ has_one :granted_by, serializer: BasicUserSerializer
This cut down the number of queries from 81 to 8 locally for me.
Not too familiar with the badge-related pages, will dig a bit deeper to make sure this has no other side effects before submitting a PR.
Is that BasicUser as in Trust Level 1 ?
AFAIK, the number of Badges a New member can get is relatively few, and progressing to Basic member is not a high hurdle. Perhaps performance can be improved by taking New out of the query for those Badges that are impossible for a New member to get and running two queries instead?
Oh no, it’s actually
Basic UserSerializer instead of
i.e. it contains much less information about a user, but should be enough for the badges page.
Sorry about the confusion!
Hmm. If you’ve replicated this, I’m going to charge this to a bug. It started when upgrading to beta 3, I believe.
As far as I can see, the change is safe. Just submitted a PR:
Didn’t test with previous versions, but I have a feeling that this has been like this for
a while. The number of queries will only increase dramatically if a user has badges granted by different staff members.
@sam, you appear to be the last to have touched this in a meaningful way.
Oooh! And I can confirm that it fixes the site where I was previously unable to open preferences or preferences/badges.