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

Bulk insert potential payments #3375

Merged
merged 17 commits into from Sep 22, 2021

Conversation

tsmartt
Copy link
Collaborator

@tsmartt tsmartt commented Aug 30, 2021

Initial stab at simplifying potential payments
We want to bulk insert these for performance reasons. We no longer send
out emails and with this, we will no longer sync connection information
for each of the wallets. That is done when a user logs in.

This lets us delete and simplify the code. I'm sure there are things
that can still be done, and might be -- but this is a first stab.

Things to be done for this PR before merge:

  • tests pass
  • Make sure all records loaded up front, so no n+1

Things that still might be done, but maybe for v2:

  • Eliminate the create_message calls and just return the objects
    for bulk insertion
  • Make uphold_service and gemini_service style like bitflyer_service

We want to bulk insert these for performance reasons. We no longer send
out emails and with this, we will no longer sync connection information
for each of the wallets. That is done when a user logs in.

This lets us delete and simplify the code. I'm sure there are things
that can still be done, and might be -- but this is a first stab.

Things to be done for this PR before merge:
- tests pass
- Make sure all records loaded up front, so no n+1

Things that still might be done, but maybe for v2:
1) Eliminate the create_message calls and just return the objects
   for bulk insertion
2) Make uphold_service and gemini_service style like bitflyer_service
@tsmartt tsmartt marked this pull request as ready for review August 31, 2021 17:49
@@ -112,8 +112,7 @@ class Publisher < ApplicationRecord
###############################

scope :uphold_selected_provider, -> {
joins("INNER JOIN uphold_connections
ON uphold_connections.id = publishers.selected_wallet_provider_id
where("uphold_connections.id = publishers.selected_wallet_provider_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm mistaken, scopes like these should still work in isolation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah these are only ever called from our job, and with eager loading it throws a double reference error to have the join here. I'll work on a workaround.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the confusing part is that below, you're using both includes and joins. Is it possible to revert back to the original definition of uphold_selected_provider, and if not, why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You need to use includes for eager loading since we enforce strict loading, but we need to joins for filtering.

@yachtcaptain23
Copy link
Contributor

Would you make it so that the code is idempotent/retryable? If the primary jobs fails part way, it doesn't seem like there's a way to restart from the middle

# Implemented in Payout::Service
return if skip_publisher?
class GeminiService
def perform(payout_report:, publisher:)
Copy link
Contributor

Choose a reason for hiding this comment

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

These were part of the same Payout::Service class to use the same initializer so we didn't have to repeat ourselves, may we revert back?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to bring these in line with the Bitflyer Service class for consistency. The methods in that class are utility classes and can be called as such; there's no need to bind these classes together in a hierarchy -- they can each just call the helper. Having it use inheritance causes a lot of pain when trying to add the Bitflyer Service class due to the complexity in that class, so we began refactoring it then. This is the completion of that work.

tsmartt and others added 4 commits September 17, 2021 15:28
@tsmartt tsmartt force-pushed the bulk-insert-potential-payments branch from 55a6ed7 to db7cb2f Compare September 21, 2021 15:24
PayoutMessage.create(
payout_report: @payout_report,
publisher: @publisher,
message: "#{self.class.name} #{message}"
message: "#{@class_name} #{message}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than passing by argument, the child class inherits this function so refactoring was unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I prefer composition, you inheritance here. I'll make the change.

@tsmartt tsmartt merged commit d5b83e4 into brave-intl:staging Sep 22, 2021
@tsmartt tsmartt deleted the bulk-insert-potential-payments branch September 22, 2021 00:01
@tsmartt tsmartt mentioned this pull request Sep 22, 2021
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