Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix loading only at single historical timestamp

ulferts9e534b157633
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rb
index 728861e71e1..1ba4cb59c20 100644
--- a/app/models/journable/with_historic_attributes.rb
+++ b/app/models/journable/with_historic_attributes.rb
@@ -138,7 +138,11 @@ class Journable::WithHistoricAttributes < SimpleDelegator
end
def matches_query_filters_at_timestamps
- timestamps.select { |timestamp| loader.work_package_ids_of_query_at_timestamp(query:, timestamp:).include?(__getobj__.id) }
+ if query.present?
+ timestamps.select { |timestamp| loader.work_package_ids_of_query_at_timestamp(query:, timestamp:).include?(__getobj__.id) }
+ else
+ []
+ end
end
def exists_at_timestamps
@@ -154,7 +158,7 @@ class Journable::WithHistoricAttributes < SimpleDelegator
end
def matches_query_filters_at_baseline_timestamp?
- query && matches_query_filters_at_timestamps.include?(baseline_timestamp)
+ matches_query_filters_at_timestamps.include?(baseline_timestamp)
end
def current_timestamp
@@ -162,11 +166,11 @@ class Journable::WithHistoricAttributes < SimpleDelegator
end
def matches_query_filters_at_current_timestamp?
- query && matches_query_filters_at_timestamps.include?(current_timestamp)
+ matches_query_filters_at_timestamps.include?(current_timestamp)
end
def matches_query_filters_at_timestamp?(timestamp)
- query && matches_query_filters_at_timestamps.include?(timestamp)
+ matches_query_filters_at_timestamps.include?(timestamp)
end
def at_timestamp(timestamp)
diff --git a/lib/api/v3/work_packages/eager_loading/base.rb b/lib/api/v3/work_packages/eager_loading/base.rb
index bd1a107d1ff..f5cc8486091 100644
--- a/lib/api/v3/work_packages/eager_loading/base.rb
+++ b/lib/api/v3/work_packages/eager_loading/base.rb
@@ -30,7 +30,7 @@ module API
module V3
module WorkPackages
module EagerLoading
- class Base < SimpleDelegator
+ class Base
def initialize(work_packages)
self.work_packages = work_packages
end
diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
index f02ce94cb5d..0ddf182ad04 100644
--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
@@ -36,9 +36,10 @@ module API::V3::WorkPackages::EagerLoading
work_package_with_historic_attributes = work_packages_with_historic_attributes[work_package.id]
- set_non_delegated_properties(work_package,
- work_package_with_historic_attributes,
- work_package_with_historic_attributes.timestamps.last.to_s)
+ set_attributes_at_timestamp(work_package,
+ work_package_with_historic_attributes,
+ work_package_with_historic_attributes.timestamps.last,
+ override_current: true)
work_package.at_timestamps = work_package_with_historic_attributes
.timestamps
@@ -46,9 +47,9 @@ module API::V3::WorkPackages::EagerLoading
wrapped_wp = AttributesByTimestampWorkPackage
.new(work_package_with_historic_attributes.at_timestamp(timestamp), timestamp)
- set_non_delegated_properties(wrapped_wp,
- work_package_with_historic_attributes,
- wrapped_wp.timestamp)
+ set_attributes_at_timestamp(wrapped_wp,
+ work_package_with_historic_attributes,
+ wrapped_wp.timestamp)
wrapped_wp
end
@@ -60,7 +61,8 @@ module API::V3::WorkPackages::EagerLoading
private
- def set_non_delegated_properties(work_package, source, timestamp)
+ def set_attributes_at_timestamp(work_package, source, timestamp, override_current: false)
+ work_package.attributes = source.attributes.except('timestamp') if override_current
work_package.matches_filters_at_timestamp = source.matches_query_filters_at_timestamps.include?(timestamp)
work_package.exists_at_timestamp = source.exists_at_timestamps.include?(timestamp)
work_package.attributes_changed_to_baseline = source.changed_at_timestamp(timestamp)
diff --git a/lib/api/v3/work_packages/work_package_eager_loading_wrapper.rb b/lib/api/v3/work_packages/work_package_eager_loading_wrapper.rb
index d5cbb52059e..6673b7e7aae 100644
--- a/lib/api/v3/work_packages/work_package_eager_loading_wrapper.rb
+++ b/lib/api/v3/work_packages/work_package_eager_loading_wrapper.rb
@@ -75,13 +75,13 @@ module API
def eager_loader_classes_all
[
+ ::API::V3::WorkPackages::EagerLoading::HistoricAttributes,
::API::V3::WorkPackages::EagerLoading::Hierarchy,
::API::V3::WorkPackages::EagerLoading::Ancestor,
::API::V3::WorkPackages::EagerLoading::Project,
::API::V3::WorkPackages::EagerLoading::Checksum,
::API::V3::WorkPackages::EagerLoading::CustomValue,
- ::API::V3::WorkPackages::EagerLoading::CustomAction,
- ::API::V3::WorkPackages::EagerLoading::HistoricAttributes
+ ::API::V3::WorkPackages::EagerLoading::CustomAction
]
end
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index 75757bee9c0..1fdcee22e0f 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -33,6 +33,8 @@ describe 'API v3 Work package resource',
content_type: :json do
include API::V3::Utilities::PathHelper
+ create_shared_association_defaults_for_work_package_factory
+
let(:work_package) do
create(:work_package,
project_id: project.id,