diff --git a/CHANGELOG.md b/CHANGELOG.md index b5637083df..36abc9f517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Fix +- Fix for removing from statistics the count of the download of plans that lack an user id in exported_plans table. Most of such downloads will have been associated with robots harvesting. + ## v5.0.2 - Bump Ruby to v3.1.4 and use `.ruby-version` in CI - [#3566](https://github.com/DMPRoadmap/roadmap/pull/3566) diff --git a/app/models/stat_exported_plan/create_or_update.rb b/app/models/stat_exported_plan/create_or_update.rb index 0ef504976c..b3fde3fb57 100644 --- a/app/models/stat_exported_plan/create_or_update.rb +++ b/app/models/stat_exported_plan/create_or_update.rb @@ -40,9 +40,11 @@ def org_plan_ids(org_id:, filtered:) .uniq end + # Exclude plans harvested by robots, by excluding plans that have a user_id nil. def exported_plans(start_date:, end_date:, org_id:, filtered:) ExportedPlan.where(plan_id: org_plan_ids(org_id: org_id, filtered: filtered)) .where(created_at: start_date..end_date) + .where.not(user_id: nil) .count end end