-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
CB-416: Identify users by musicbrainz username, not uuid #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start, thanks for the work.
I added 2 comments about abstracting out some code into a helper/utility so that we don't have to rewrite the same thing each time.
We should also add some tests to make sure that the endpoints that work with usernames can handle these cases. We should try 1) a uuid, 2) a username which is the current logged in user, and 3) a username which isn't the current logged in user.
As we discussed in IRC, don't worry about the case where a username is a uuid. If it's a uuid, always assume that it's a user id.
AFAIR, CB doesn't update the MusicBrainz usernames when the MB username is updated. We should probably add that (separate PR is fine) as well so that when MB username changes, the CB db is updated as well. We do this in LB like this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing changes look good to me but I think we can do some further simplifications. We can have a single method to query users and also retrieve the user_ref in the same query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Thanks!
With #403, we perform a check as `"user".id::text = :user_ref`. `:user_ref` can be a username or a uuid, therefore we need to cast "user".id to text so that the comparison succeeds without error in case :user_ref is a username. Casting to text, however disables the use of any uuid indexes we may have on "user".id so add a new index on "user".id::text. critiquebrainz_db=> begin; BEGIN critiquebrainz_db=> explain analyze select * from "user" where id::text = 'amCap1712'; QUERY PLAN --------------------------------------------------------------------------------------------------- Seq Scan on "user" (cost=0.00..77.18 rows=13 width=78) (actual time=2.317..2.317 rows=0 loops=1) Filter: ((id)::text = 'amCap1712'::text) Rows Removed by Filter: 2631 Planning Time: 0.069 ms Execution Time: 2.336 ms (5 rows) critiquebrainz_db=> CREATE INDEX ix_user_id ON "user" USING btree ((id::text)); CREATE INDEX critiquebrainz_db=> explain analyze select * from "user" where id::text = 'amCap1712'; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------- Index Scan using ix_user_id on "user" (cost=0.28..12.51 rows=13 width=78) (actual time=0.128..0.128 rows=0 loops=1) Index Cond: ((id)::text = 'amCap1712'::text) Planning Time: 0.328 ms Execution Time: 0.158 ms (4 rows) critiquebrainz_db=> rollback; ROLLBACK
Identify users by username (if they are linked with MB account) and by UUID (if they are not linked with MB account).