|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Wings |
| 4 | + # OVERRIDE Hyrax v3.6.0 to backport a bug fix from v5.0.1. |
| 5 | + # This override is no longer needed when Hyrax's version is >= v5.0.1 |
| 6 | + # |
| 7 | + # Work forms were throwing 504 time out errors because large AdminSets |
| 8 | + # being queried by Hyrax#query_service were loading all of their members. |
| 9 | + # |
| 10 | + # @see https://github.com/samvera/hyrax/commit/75312ee |
| 11 | + module AttributeTransformerDecorator |
| 12 | + # OVERRIDE: Replace contents of this method with the version found in v5.0.1 |
| 13 | + def run(obj) |
| 14 | + attrs = obj.reflections.each_with_object({}) do |(key, reflection), mem| |
| 15 | + case reflection |
| 16 | + when ActiveFedora::Reflection::HasManyReflection, |
| 17 | + ActiveFedora::Reflection::HasAndBelongsToManyReflection, |
| 18 | + ActiveFedora::Reflection::IndirectlyContainsReflection |
| 19 | + mem[:"#{key.to_s.singularize}_ids"] = |
| 20 | + obj.association(key).ids_reader |
| 21 | + when ActiveFedora::Reflection::DirectlyContainsReflection |
| 22 | + mem[:"#{key.to_s.singularize}_ids"] = |
| 23 | + Array(obj.public_send(reflection.name)).map(&:id) |
| 24 | + when ActiveFedora::Reflection::FilterReflection, |
| 25 | + ActiveFedora::Reflection::OrdersReflection, |
| 26 | + ActiveFedora::Reflection::HasSubresourceReflection, |
| 27 | + ActiveFedora::Reflection::BelongsToReflection, |
| 28 | + ActiveFedora::Reflection::BasicContainsReflection |
| 29 | + :noop |
| 30 | + when ActiveFedora::Reflection::DirectlyContainsOneReflection |
| 31 | + mem[:"#{key.to_s.singularize}_id"] = |
| 32 | + obj.public_send(reflection.name)&.id |
| 33 | + else |
| 34 | + mem[reflection.foreign_key.to_sym] = |
| 35 | + obj.public_send(reflection.foreign_key.to_sym) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + obj.class.delegated_attributes.keys.each_with_object(attrs) do |attr_name, mem| |
| 40 | + next unless obj.respond_to?(attr_name) && !mem.key?(attr_name.to_sym) |
| 41 | + mem[attr_name.to_sym] = TransformerValueMapper.for(obj.public_send(attr_name)).result |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | +end |
| 46 | + |
| 47 | +Wings::AttributeTransformer.singleton_class.send(:prepend, Wings::AttributeTransformerDecorator) |
0 commit comments