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

Move references to user_storage_ids_table to one place #44801

Merged
merged 12 commits into from
Feb 23, 2022

Conversation

maureensturgeon
Copy link
Contributor

@maureensturgeon maureensturgeon commented Feb 11, 2022

The intent of this PR is to replace references to PEGASUS_DB[:user_storage_ids] with helper methods to create a layer of abstraction and have less direct references to the table since the table is going to change. Note that there are still direct queries through joins in projects_list.rb which don't make sense to replace.

For a sneak peek of where this could be headed see: https://github.com/code-dot-org/code-dot-org/pull/44957/files

One option that I was considering was making a new class UserStorageIds which would have methods like get_by_id, get_by_user_id, exists? and create, but I wasn't sure if it was worth the effort because we'll be replacing a lot of this code soon anyway.

Testing story

This is a refactor with no increase in test coverage, however I did update some unit tests where it made sense.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@maureensturgeon maureensturgeon force-pushed the maureen/user-storage-ids-query-consolidation branch from 77e595d to 9e7ba06 Compare February 21, 2022 17:30
@maureensturgeon maureensturgeon marked this pull request as ready for review February 22, 2022 01:29
@maureensturgeon maureensturgeon requested a review from a team February 22, 2022 01:29
Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

Great idea to do this step!

Comment on lines 231 to 237
# For the given user id, looks up the storage id, or creates a new one if the user doesn't have one.
def self.find_or_create_storage_id_for_user_id(user_id)
environment_check!
row = user_storage_ids_table.where(user_id: user_id)
return row[:id] if row
user_storage_ids_table.insert(user_id: user_id)
storage_id = storage_id_for_user_id(user_id)
return storage_id if storage_id
create_storage_id_for_user(user_id)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole helper method seems like something that should exist in storage_id.rb. We might even be able to avoid exposing create_storage_id_for_user directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method looks like it's only used in this sample_data file for creating test data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Maybe we can make it clearer that create_storage_id_for_user should only be used for test purposes, either with a comment on the method or by renaming it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I'll update the comment.

@maureensturgeon maureensturgeon merged commit 0a06ad7 into staging Feb 23, 2022
@maureensturgeon maureensturgeon deleted the maureen/user-storage-ids-query-consolidation branch February 23, 2022 23:45
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.

None yet

2 participants