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

CV2-2648 Refactor Tipline requests #1743

Merged
merged 60 commits into from
Jan 28, 2024

Conversation

melsawy
Copy link
Contributor

@melsawy melsawy commented Nov 27, 2023

Description

Convert smooch annotations to a new model TiplineRequest through the following steps:

  • Convert smooch fields to a new model TiplineRequest and create new fields from smooch_data (language, tipline_user_uid and platform) to make PG queries fast
  • Remove smooch fields migration
  • Store requests in a new model instead of smooch annotations
  • Fix ES for tipline requests
  • Fix cached fields related to smooch annotations
  • Fix team rules
  • Fix seed file
  • Fix check statistics

References: CV2-2648

How has this been tested?

Fix existing tests and make sure travis tests passed.
Run tipline integration locally

Things to pay attention to during code review

Please describe parts of the change that require extra attention during code review, for example:

  • File FFFF, line LL: This refactoring does this and this. Is it consistent with how it’s implemented elsewhere?
  • Etc.

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

@melsawy melsawy changed the title Refactor/cv2 2648 refactor tipline requests CV2-2648 Refactor Tipline requests Dec 4, 2023
@melsawy melsawy marked this pull request as ready for review December 5, 2023 06:18
Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

Great work Sawy! Getting there!

Comment on lines +6 to +13
conditions = {
created_at: start_date..end_date,
team_id: team_id,
language: language,
platform: platform
}
conditions[:smooch_request_type] = type unless type.nil?
TiplineRequest.where(conditions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Way cleaner!

times << (f.created_at - f.annotation.created_at)
reports_received(team_id, platform, start_date, end_date, language).find_each do |tr|
# TODO: review with Caio
times << (tr.updated_at - tr.created_at)
end
median_response_time_in_seconds = times.size == 0 ? nil : times.sum.to_f / times.size
statistics[:median_response_time] = median_response_time_in_seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

The rest of the changes here look good, but please run the rake task to be sure.

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 do

Copy link
Contributor

Choose a reason for hiding this comment

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

@melsawy , did you run the rake task?

t.string :language, index: true
t.string :tipline_user_uid, index: true
t.string :platform, index: true
t.text :smooch_request_type, null: true
Copy link
Contributor

Choose a reason for hiding this comment

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

Request type can't be null.

@@ -16,7 +16,7 @@ def requests(team_id, platform, start_date, end_date, language, type = nil)
def reports_received(team_id, platform, start_date, end_date, language)
TiplineRequest
.where(team_id: team_id, language: language, created_at: start_date..end_date, platform: platform)
.where('smooch_report_received_at IS NOT NULL')
.where.not(smooch_report_received_at: 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can still be NULL, no? I think it's more robust to change this condition to:

.where('smooch_report_received_at > 0')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No as I set the default value to 0 in migration file so it'll be a value or 0

times << (f.created_at - f.annotation.created_at)
reports_received(team_id, platform, start_date, end_date, language).find_each do |tr|
# TODO: review with Caio
times << (tr.updated_at - tr.created_at)
end
median_response_time_in_seconds = times.size == 0 ? nil : times.sum.to_f / times.size
statistics[:median_response_time] = median_response_time_in_seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

@melsawy , did you run the rake task?

@@ -0,0 +1,220 @@
namespace :check do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document here (as a comment, first line of the file) how to call the rake tasks (expected args, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Already I added a line before rake task definition bundle exec rails check:migrate:migrate_tipline_requests

Copy link
Contributor

Choose a reason for hiding this comment

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

Why this file was deleted? No more useful tests here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this file contains only one test and no more useful

@@ -159,7 +159,8 @@ def before_all
# This will run before any test

def setup
[Account, Media, ProjectMedia, User, Source, Annotation, Team, TeamUser, Relationship, Project, TiplineResource].each{ |klass| klass.delete_all }
puts "[Starting test #{self.class.name}::#{self.method_name}]" # Output which test has started running
Copy link
Contributor

Choose a reason for hiding this comment

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

Please comment this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -195,6 +196,7 @@ def setup
# This will run after any test

def teardown
puts "[Finishing test #{self.class.name}::#{self.method_name}]" # Output which test has finished running
Copy link
Contributor

Choose a reason for hiding this comment

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

Please comment this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@melsawy melsawy requested a review from caiosba January 9, 2024 05:19
@melsawy
Copy link
Contributor Author

melsawy commented Jan 9, 2024

@caiosba I applied latest comments and asked @sonoransun for a recent live dump so I can verify tipline refactor rake task and statistic rake task

Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

Thanks @melsawy - please re-request my review once the other issues are fixed too (see testing sheet).

@melsawy melsawy requested a review from caiosba January 23, 2024 16:05
@melsawy
Copy link
Contributor Author

melsawy commented Jan 23, 2024

@caiosba please review the latest changes and please verify rake tasks on your local machine

  • bundle exec rake check:data:statistics
  • bundle exec rails check:migrate:migrate_tipline_requests

Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

@melsawy , I just reviewed the latest changes to the PR and tested the migration and statistic rake tasks locally. All good except for one thing: the “average time for publishing” data point is not being calculated correctly (or maybe the data points involved were not migrated correctly?). More details in Jira.

@melsawy melsawy requested a review from caiosba January 24, 2024 09:20
Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

Sawy, it still doesn't work. I added more details to the Jira ticket.

@melsawy melsawy requested a review from caiosba January 27, 2024 16:30
Copy link

codeclimate bot commented Jan 27, 2024

Code Climate has analyzed commit 69b6f16 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (100% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

Copy link
Contributor

@caiosba caiosba left a comment

Choose a reason for hiding this comment

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

Thanks @melsawy , the statistics rake task works for me now.

@melsawy melsawy merged commit f5debd5 into develop Jan 28, 2024
8 checks passed
@melsawy melsawy deleted the refactor/CV2-2648-refactor-tipline-requests branch January 28, 2024 06:01
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.

2 participants