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/duplication exception #89

Merged
merged 3 commits into from
Sep 5, 2023
Merged

Fix/duplication exception #89

merged 3 commits into from
Sep 5, 2023

Conversation

dvilelaf
Copy link
Collaborator

@dvilelaf dvilelaf commented Sep 4, 2023

Proposed changes

Ignores twet registrations for addresses that have been already registered

Fixes

n/a

Types of changes

What types of changes does your code introduce? (A breaking change is a fix or feature that would cause existing functionality and APIs to not work as expected.)
Put an x in the box that applies

  • Non-breaking fix (non-breaking change which fixes an issue)
  • Breaking fix (breaking change which fixes an issue)
  • Non-breaking feature (non-breaking change which adds functionality)
  • Breaking feature (breaking change which adds functionality)
  • Refactor (non-breaking change which changes implementation)
  • Messy (mixture of the above - requires explanation!)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the main branch (left side). Also you should start your branch off our main.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have locally run services that could be impacted and they do not present failures derived from my changes

Further comments

n/a

Comment on lines +752 to +763
address_to_twitter_handles = {
user["wallet_address"]: user["twitter_handle"]
for user in self.synchronized_data.ceramic_db["users"]
if user["wallet_address"]
}

# Ignore registration if both address and Twitter handle already exist
if (
wallet_address in address_to_twitter_handles
and address_to_twitter_handles[wallet_address]
):
return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the ceramic_db contains two users with the same wallet address and different handles, then this logic might fail to register one of the handles.
Can this ever happen, i.e., the db containing two users with the same address and different handles?
If yes, is it intentional not to register one of the handles?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do not allow the same address being registered with two users. In fact, we have some logic to merge users that share the same address.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, so the wallet_address is safe to be used as a unique ID here.

What worries me though is that we re-construct this mapping for every tweet:

for tweet in tweets.values():
author_id = tweet["author_id"]
twitter_name = tweet["username"]
new_points = tweet["points"]
wallet_address = self.get_registration(tweet["text"])

The address_to_twitter_handles could be generated only once and then kept in memory and used on every iteration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't do it for every tweet , but for every registration tweet, which are not very common (users only post those tweets when they register to the service). Anyway, I also thought about keeping it in memory, but since this adds to the pile of data that the service needs to keep updated and in sync, and given that we are going to revamp the registration system with a proper signature-based one, I decided to go this way.

@Adamantios Adamantios merged commit 15e4ce3 into main Sep 5, 2023
19 checks passed
@Adamantios Adamantios deleted the fix/duplication-exception branch September 5, 2023 11:18
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