app/controllers/concepts/hierarchical_controller.rb in iqvoc-4.13.2 vs app/controllers/concepts/hierarchical_controller.rb in iqvoc-4.14.4

- old
+ new

@@ -14,26 +14,28 @@ # See the License for the specific language governing permissions and # limitations under the License. class Concepts::HierarchicalController < ConceptsController def index + base_class = Iqvoc::Concept.base_class + if params[:published] == '0' - authorize! :update, Iqvoc::Concept.base_class + authorize! :update, base_class else - authorize! :read, Iqvoc::Concept.base_class + authorize! :read, base_class end - scope = Iqvoc::Concept.base_class.includes(:pref_labels).order('labels.value') + scope = base_class.includes(base_class.default_includes + [:pref_labels]).order('labels.value') scope = params[:published] == '0' ? scope.published_with_newer_versions : scope.published + # only select unexpired concepts + scope = scope.not_expired + # unrelated concepts for sidebar # TODO: order parentless concepts @loose_concepts = scope.parentless.includes(:pref_labels).page(params[:page]) - # only select unexpired concepts - scope = scope.not_expired - # if params[:broader] is given, the action is handling the reversed tree root_id = params[:root] if root_id && root_id =~ /\d+/ # NB: order matters; see the following `where` if params[:broader] @@ -48,15 +50,10 @@ else @concepts = scope.tops.includes(:narrower_relations).references(:concepts) end end - # When in single query mode, AR handles ALL includes to be loaded by that - # one query. We don't want that! So let's do it manually :-) - ActiveRecord::Associations::Preloader.new.preload(@concepts, - Iqvoc::Concept.base_class.default_includes + [:pref_labels]) - respond_to do |format| format.html format.json do # Treeview data concepts = @concepts.select { |c| can? :read, c }.map do |c| url = (c.published?) ? concept_path(id: c, format: :html) : concept_path(id: c, format: :html, published: 0) @@ -73,11 +70,10 @@ additionalText: (" (#{c.additional_info})" if c.additional_info.present?), load_on_demand: load_on_demand, url: url, update_url: move_concept_url(c), glance_url: glance_concept_url(c, format: :html), - published: (c.published?) ? true : false, - locked: (can?(:branch, c) || can?(:update, c) ? false : true) + published: (c.published?) ? true : false } end render json: concepts end end