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

Fix user search duplicate bug #260

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

amirRamirfatahi
Copy link
Collaborator

@amirRamirfatahi amirRamirfatahi commented Dec 20, 2024

Fixes #259

Pre-submission Checklist

For tests to work you need a working neo4j and redis instance with the example dataset in docker/db-graph

  • [*] Testing: Implement and pass new tests for the new features/fixes, cargo test.
  • Performance: Ensure new code has relevant performance benchmarks, cargo bench

Copy link
Collaborator

@SHAcollision SHAcollision left a comment

Choose a reason for hiding this comment

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

The proposed solution to this bug works.

However, the solution is overly complex. Adding a new Hashmap to find Usernames by pubky_id does not seem necessary. This lookup table is not needed as we already have methods to retrieve a username of any user by its pubky_id. We already have User:Details:{user_id} keys that we can access with UserDetails::get_by_id(pubky_id).username . This is enough to figure what username:pubky_id (if any) we should remove from the sorted set.

let mut records_to_delete: Vec<String> = Vec::with_capacity(user_ids.len());
for user_id in user_ids {
let existing_record =
Self::try_from_index_hashmap(&USER_NAME_HASHMAP_KEY_PARTS, user_id).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not simply do UserDetails::get_bt_id(user_id) to figure what this user's current username (if any) is?

Comment on lines +61 to +69
// ensure existing records are deleted
Self::delete_existing_records(
details_list
.iter()
.map(|details| details.id.0.as_str())
.collect::<Vec<&str>>()
.as_slice(),
)
.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice.

@@ -72,9 +84,21 @@ impl UserSearch {
// The value in the sorted set will be `username:user_id`
let member = format!("{}:{}", username, user_id.0);

hashmap_items.push((user_id.0.clone(), username.clone()));
Copy link
Collaborator

@SHAcollision SHAcollision Jan 1, 2025

Choose a reason for hiding this comment

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

Not really needed, unless we can proof some sort of performance gain by maintaining this hashmap vs retrieving the usernames from the existing Redis JSON per user. Even if there is some performance improvement: switching username by the watcher will be rare and not performance sensitive (no problem if it's slow as the watcher runs in the background).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔮 nexus 👀 watcher
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug (watcher): changing username duplicates the user on the search by username response
2 participants