Skip to content

Commit 17853eb

Browse files
committed
minor fixes for HasContentTags
refs CNVS-6947 * don't look for them on folders * don't do updates if no tags were found test plan: * from the UI, download a zip of a folder * check the log for the ContentZipper job that created the zip * there shouldn't be a query against content_tags Change-Id: I51097956a2ee4d77f42f2019c6e563280af8f296 Reviewed-on: https://gerrit.instructure.com/22410 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jacob Fugal <jacob@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com>
1 parent 1f2ef01 commit 17853eb

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

app/models/content_tag.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ def available_for?(user, opts={})
264264

265265
def self.update_for(asset)
266266
tags = ContentTag.where(:content_id => asset, :content_type => asset.class.to_s).not_deleted.select([:id, :tag_type, :content_type, :context_module_id]).all
267-
module_ids = tags.select{|t| t.context_module_id }.map(&:context_module_id)
267+
module_ids = tags.map(&:context_module_id).compact
268268

269269
# update title
270270
tag_ids = tags.select{|t| t.sync_title_to_asset_title? }.map(&:id)
271271
attr_hash = {:updated_at => Time.now.utc}
272272
{:display_name => :title, :name => :title, :title => :title}.each do |attr, val|
273273
attr_hash[val] = asset.send(attr) if asset.respond_to?(attr)
274274
end
275-
ContentTag.where(:id => tag_ids).update_all(attr_hash)
275+
ContentTag.where(:id => tag_ids).update_all(attr_hash) unless tag_ids.empty?
276276

277277
# update workflow_state
278278
tag_ids = tags.select{|t| t.sync_workflow_state_to_asset? }.map(&:id)
@@ -284,7 +284,7 @@ def self.update_for(asset)
284284
attr_hash[:workflow_state] = asset.workflow_state
285285
end
286286
end
287-
ContentTag.where(:id => tag_ids).update_all(attr_hash) if attr_hash[:workflow_state]
287+
ContentTag.where(:id => tag_ids).update_all(attr_hash) if attr_hash[:workflow_state] && !tag_ids.empty?
288288

289289
ContentTag.touch_context_modules(module_ids)
290290
end

lib/has_content_tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def update_associated_content_tags
2929
def check_if_associated_content_tags_need_updating
3030
@associated_content_tags_need_updating = false
3131
return if self.new_record?
32-
return if self.respond_to?(:context_type) && self.context_type == 'SisBatch'
32+
return if self.respond_to?(:context_type) && %w{SisBatch Folder}.include?(self.context_type)
3333
@associated_content_tags_need_updating = true if self.respond_to?(:title_changed?) && self.title_changed?
3434
@associated_content_tags_need_updating = true if self.respond_to?(:name_changed?) && self.name_changed?
3535
@associated_content_tags_need_updating = true if self.respond_to?(:display_name_changed?) && self.display_name_changed?

0 commit comments

Comments
 (0)