Skip to content
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

Merged
merged 11 commits into from
Oct 4, 2022

Conversation

anshg1214
Copy link
Member

Identify users by username (if they are linked with MB account) and by UUID (if they are not linked with MB account).

Copy link
Collaborator

@alastair alastair left a 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.

critiquebrainz/frontend/templates/log/action.html Outdated Show resolved Hide resolved
critiquebrainz/frontend/views/user.py Outdated Show resolved Hide resolved
@amCap1712
Copy link
Member

amCap1712 commented Aug 30, 2022

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

https://github.com/metabrainz/listenbrainz-server/blob/f70ced5224db30bff17e31fe760c94305cb6f6de/listenbrainz/webserver/login/provider.py#L62-L65

Copy link
Member

@amCap1712 amCap1712 left a 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.

@anshg1214 anshg1214 requested review from amCap1712 and removed request for alastair October 3, 2022 07:58
Copy link
Member

@amCap1712 amCap1712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@alastair alastair merged commit fc5f267 into metabrainz:master Oct 4, 2022
@github-actions
Copy link

github-actions bot commented Oct 4, 2022

Unit Test Results

    1 files  ±0      1 suites  ±0   2m 11s ⏱️ ±0s
198 tests ±0  198 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit fc5f267. ± Comparison against base commit fc5f267.

amCap1712 added a commit that referenced this pull request Oct 4, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants