Skip to content

Commit

Permalink
Merge pull request #360 from openstax/memory-usage-fixes
Browse files Browse the repository at this point in the history
use find_each instead of each
  • Loading branch information
chrisbendel authored Mar 28, 2024
2 parents 0fdf9e0 + e0f90e0 commit a24db36
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions backend/app/services/learner_activity_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def build_headers(csv)
end

def get_users(launches)
launches.each do |launch|
@user_uuids << launch.user_id
end
@user_uuids = launches.clone.pluck('user_id')

UserInfo.for_uuids(@user_uuids)
end

Expand All @@ -48,7 +47,7 @@ def find_user_email(account)
end

def build_rows(csv, users, launches)
launches.each do |launch|
launches.includes(:stage, :research_id, study: :first_launched_study).find_each do |launch|
next if launch.stage.study.first_launched_study.opted_out_at

account = users[launch.user_id] || {}
Expand All @@ -73,7 +72,7 @@ def build_rows(csv, users, launches)

def generate_report(csv)
launches = LaunchedStage
.joins(:research_id, stage: :study)
.joins(stage: :study)
.where('first_launched_at >= ?', (@months_ago || 1).to_i.months.ago)

users = get_users(launches)
Expand Down

0 comments on commit a24db36

Please sign in to comment.