From 7d88b3b0c77d3f621fa841398e5a1b7a70e04025 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Thu, 15 Aug 2019 08:57:36 +0100 Subject: [PATCH] use single query to invalidate cache for all affected work packages --- ...648_add_derived_estimated_hours_to_work_packages.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb index 679014f90a..9d89bc784a 100644 --- a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb +++ b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb @@ -45,7 +45,7 @@ class AddDerivedEstimatedHoursToWorkPackages < ActiveRecord::Migration[5.2] create_customizable_journals last_id: last_id create_attachable_journals last_id: last_id - work_packages.each(&:touch) # invalidate cache + touch_work_packages work_packages # to invalidate cache end ## @@ -164,4 +164,12 @@ class AddDerivedEstimatedHoursToWorkPackages < ActiveRecord::Migration[5.2] WHERE #{journals}.id > #{last_id} -- make sure to only create entries for the newly created journals ") end + + def touch_work_packages(work_packages) + where = work_packages.arel.where_sql + + WorkPackage.connection.execute(" + UPDATE work_packages SET updated_at = NOW(), lock_version = lock_version + 1 #{where} + ") + end end