explicit utc db times in update_all

update_all's update hash doesn't have any magic performed on bare Time
objects; it assumes any Time object it's given is already in UTC. using
a TimeWithZone object (regardless of timezone), which Fixnum#ago and
friends happen to return, is still fine.

Change-Id: I297b2a3211b896b5225ebcfaaee3c1eb56e55fb6
Reviewed-on: https://gerrit.instructure.com/5351
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
This commit is contained in:
Jacob Fugal 2011-08-30 16:13:41 -06:00
parent 50926fc166
commit 1a761c2d1f
29 changed files with 43 additions and 43 deletions

View File

@ -118,7 +118,7 @@ class AssignmentGroupsController < ApplicationController
group_ids = ([@group.id] + (order.empty? ? [] : @context.assignments.find_all_by_id(order).map(&:assignment_group_id))).uniq.compact
Assignment.update_all("assignment_group_id=#{@group.id}", :id => order, :context_id => @context.id, :context_type => @context.class.to_s)
@group.assignments.first.update_order(order) unless @group.assignments.empty?
AssignmentGroup.update_all({:updated_at => Time.now}, {:id => group_ids})
AssignmentGroup.update_all({:updated_at => Time.now.utc}, {:id => group_ids})
ids = @group.assignments.map(&:id)
@context.recompute_student_scores rescue nil
respond_to do |format|
@ -187,7 +187,7 @@ class AssignmentGroupsController < ApplicationController
order = @new_group.assignments.active.map(&:id)
ids_to_change = @assignment_group.assignments.active.map(&:id)
order += ids_to_change
Assignment.update_all({:assignment_group_id => @new_group.id, :updated_at => Time.now}, {:id => ids_to_change}) unless ids_to_change.empty?
Assignment.update_all({:assignment_group_id => @new_group.id, :updated_at => Time.now.utc}, {:id => ids_to_change}) unless ids_to_change.empty?
Assignment.find_by_id(order).update_order(order) unless order.empty?
@new_group.touch
@assignment_group.reload

View File

@ -234,7 +234,7 @@ class ContextModulesController < ApplicationController
item.context_module_id = @module.id
item.save
end
ContextModule.update_all({:updated_at => Time.now}, {:id => affected_module_ids})
ContextModule.update_all({:updated_at => Time.now.utc}, {:id => affected_module_ids})
@context.touch
@module.reload
respond_to do |format|

View File

@ -222,7 +222,7 @@ class OutcomesController < ApplicationController
if @asset
@all_tags = ContentTag.learning_outcome_tags_for(@asset)
end
@asset.class.update_all({:updated_at => Time.now}, {:id => @asset.id})
@asset.class.update_all({:updated_at => Time.now.utc}, {:id => @asset.id})
render :json => @all_tags.to_json(:include => :learning_outcome)
end
end

View File

@ -16,7 +16,7 @@ class AccountNotification < ActiveRecord::Base
end
def touch_account
Account.update_all({:updated_at => Time.now}, {:id => self.account_id}) if self.account_id
Account.update_all({:updated_at => Time.now.utc}, {:id => self.account_id}) if self.account_id
end
named_scope :for_account, lambda{|account|

View File

@ -128,7 +128,7 @@ class Assignment < ActiveRecord::Base
end
def touch_assignment_group
AssignmentGroup.update_all({:updated_at => Time.now}, {:id => self.assignment_group_id}) if self.assignment_group_id
AssignmentGroup.update_all({:updated_at => Time.now.utc}, {:id => self.assignment_group_id}) if self.assignment_group_id
true
end
@ -703,7 +703,7 @@ class Assignment < ActiveRecord::Base
send_later_if_production(:multiple_module_actions, context.students.map(&:id), :scored, score)
changed_since_publish = !!self.available?
Submission.update_all({:score => score, :grade => grade, :published_score => score, :published_grade => grade, :changed_since_publish => changed_since_publish, :workflow_state => 'graded', :graded_at => Time.now}, {:id => submissions_to_save.map(&:id)} ) unless submissions_to_save.empty?
Submission.update_all({:score => score, :grade => grade, :published_score => score, :published_grade => grade, :changed_since_publish => changed_since_publish, :workflow_state => 'graded', :graded_at => Time.now.utc}, {:id => submissions_to_save.map(&:id)} ) unless submissions_to_save.empty?
end
def update_user_from_rubric(user, assessment)

View File

@ -925,7 +925,7 @@ class Attachment < ActiveRecord::Base
self.file_state = 'deleted' #destroy
self.deleted_at = Time.now
ContentTag.delete_for(self)
MediaObject.update_all({:workflow_state => 'deleted', :updated_at => Time.now}, {:attachment_id => self.id}) if self.id && delete_media_object
MediaObject.update_all({:workflow_state => 'deleted', :updated_at => Time.now.utc}, {:attachment_id => self.id}) if self.id && delete_media_object
save!
end

View File

@ -273,7 +273,7 @@ class CommunicationChannel < ActiveRecord::Base
self.save!
if old_user_id
Pseudonym.update_all({:user_id => user.id}, {:user_id => old_user_id, :unique_id => self.path})
User.update_all({:updated_at => Time.now}, {:id => [old_user_id, user.id]})
User.update_all({:updated_at => Time.now.utc}, {:id => [old_user_id, user.id]})
end
end
end

View File

@ -56,12 +56,12 @@ class ContentTag < ActiveRecord::Base
end
def self.touch_context_modules(ids=[])
ContextModule.update_all({:updated_at => Time.now}, {:id => ids}) unless ids.empty?
ContextModule.update_all({:updated_at => Time.now.utc}, {:id => ids}) unless ids.empty?
true
end
def touch_context_if_learning_outcome
self.context_type.constantize.update_all({:updated_at => Time.now}, {:id => self.context_id}) if self.tag_type == 'learning_outcome_association' || self.tag_type == 'learning_outcome'
self.context_type.constantize.update_all({:updated_at => Time.now.utc}, {:id => self.context_id}) if self.tag_type == 'learning_outcome_association' || self.tag_type == 'learning_outcome'
end
def default_values
@ -181,7 +181,7 @@ class ContentTag < ActiveRecord::Base
tags = ContentTag.find(:all, :conditions => ['content_id = ? AND content_type = ?', asset.id, asset.class.to_s], :select => 'id, tag_type, context_module_id')
tag_ids = tags.select{|t| t.sync_title_to_asset_title? }.map(&:id)
module_ids = tags.select{|t| t.context_module_id }.map(&:context_module_id)
attr_hash = {:updated_at => Time.now}
attr_hash = {:updated_at => Time.now.utc}
{:display_name => :title, :name => :title, :title => :title}.each do |attr, val|
attr_hash[val] = asset.send(attr) if asset.respond_to?(attr)
end

View File

@ -65,7 +65,7 @@ class ContextModule < ActiveRecord::Base
def destroy
self.workflow_state = 'deleted'
self.deleted_at = Time.now
ContentTag.update_all({:workflow_state => 'deleted', :updated_at => Time.now}, {:context_module_id => self.id})
ContentTag.update_all({:workflow_state => 'deleted', :updated_at => Time.now.utc}, {:context_module_id => self.id})
self.send_later_if_production(:update_downstreams, self.position)
save!
true

View File

@ -570,7 +570,7 @@ class Course < ActiveRecord::Base
something_changed = true if section.send(field) != section.send("#{field}_was")
end
if something_changed
attr_hash = {:updated_at => Time.now}
attr_hash = {:updated_at => Time.now.utc}
fields_to_possibly_rename.each { |key| attr_hash[key] = section.send(key) }
CourseSection.update_all(attr_hash, {:id => section.id})
end
@ -592,8 +592,8 @@ class Course < ActiveRecord::Base
when 'MySQL'
Enrollment.connection.execute("UPDATE users, enrollments SET users.updated_at=NOW(), enrollments.updated_at=NOW() WHERE users.id=enrollments.user_id AND enrollments.course_id=#{self.id}")
else
Enrollment.update_all({:updated_at => Time.now}, :course_id => self.id)
User.update_all({:updated_at => Time.now}, "id IN (SELECT user_id FROM enrollments WHERE course_id=#{self.id})")
Enrollment.update_all({:updated_at => Time.now.utc}, :course_id => self.id)
User.update_all({:updated_at => Time.now.utc}, "id IN (SELECT user_id FROM enrollments WHERE course_id=#{self.id})")
end
end

View File

@ -45,12 +45,12 @@ class CourseSection < ActiveRecord::Base
def touch_all_enrollments
return if new_record?
self.enrollments.update_all(:updated_at => Time.now)
self.enrollments.update_all(:updated_at => Time.now.utc)
case User.connection.adapter_name
when 'MySQL'
User.connection.execute("UPDATE users, enrollments SET users.updated_at=NOW() WHERE users.id=enrollments.user_id AND enrollments.course_section_id=#{self.id}")
else
User.update_all({:updated_at => Time.now}, "id IN (SELECT user_id FROM enrollments WHERE course_section_id=#{self.id})")
User.update_all({:updated_at => Time.now.utc}, "id IN (SELECT user_id FROM enrollments WHERE course_section_id=#{self.id})")
end
end

View File

@ -182,7 +182,7 @@ class DiscussionEntry < ActiveRecord::Base
def update_topic
if self.discussion_topic
DiscussionTopic.update_all({:last_reply_at => Time.now, :updated_at => Time.now}, {:id => self.discussion_topic_id})
DiscussionTopic.update_all({:last_reply_at => Time.now.utc, :updated_at => Time.now.utc}, {:id => self.discussion_topic_id})
if self.discussion_topic.for_assignment? && self.discussion_topic.assignment.context.students.include?(self.user)
submission ||= self.discussion_topic.assignment.submit_homework(self.user, :submission_type => 'discussion_topic')
end

View File

@ -113,7 +113,7 @@ class DiscussionTopic < ActiveRecord::Base
self.context_module_tag.confirm_valid_module_requirements
end
if @old_assignment_id
Assignment.update_all({:workflow_state => 'deleted', :updated_at => Time.now}, {:id => @old_assignment_id, :context_id => self.context_id, :context_type => self.context_type, :submission_types => 'discussion_topic'})
Assignment.update_all({:workflow_state => 'deleted', :updated_at => Time.now.utc}, {:id => @old_assignment_id, :context_id => self.context_id, :context_type => self.context_type, :submission_types => 'discussion_topic'})
ContentTag.delete_for(Assignment.find(@old_assignment_id)) if @old_assignment_id
elsif self.assignment && @saved_by != :assignment
self.assignment.title = self.title

View File

@ -42,7 +42,7 @@ class EnrollmentTerm < ActiveRecord::Base
def touch_all_courses
return if new_record?
Course.update_all({:updated_at => Time.now}, "enrollment_term_id=#{self.id}")
Course.update_all({:updated_at => Time.now.utc}, "enrollment_term_id=#{self.id}")
end
def update_courses_later

View File

@ -137,7 +137,7 @@ class Group < ActiveRecord::Base
def close_memberships_if_deleted
return unless self.deleted?
memberships = self.group_memberships
User.update_all({:updated_at => Time.now}, {:id => memberships.map(&:user_id).uniq})
User.update_all({:updated_at => Time.now.utc}, {:id => memberships.map(&:user_id).uniq})
GroupMembership.update_all({:workflow_state => 'deleted'}, {:id => memberships.map(&:id).uniq})
end

View File

@ -89,7 +89,7 @@ class GroupMembership < ActiveRecord::Base
def touch_groups
groups_to_touch = [ self.group_id ]
groups_to_touch << self.old_group_id if self.old_group_id
Group.update_all({ :updated_at => Time.now }, { :id => groups_to_touch })
Group.update_all({ :updated_at => Time.now.utc }, { :id => groups_to_touch })
end
protected :touch_groups

View File

@ -172,7 +172,7 @@ class LearningOutcome < ActiveRecord::Base
ids.each do |id|
to_delete << id unless tags.any?{|t| t.content_id == id }
end
LearningOutcome.update_all({:workflow_state => 'deleted', :updated_at => Time.now}, {:id => to_delete})
LearningOutcome.update_all({:workflow_state => 'deleted', :updated_at => Time.now.utc}, {:id => to_delete})
end
def self.enabled?

View File

@ -311,7 +311,7 @@ class Pseudonym < ActiveRecord::Base
self.save
if old_user_id
CommunicationChannel.update_all({:user_id => user.id}, {:path => self.unique_id, :user_id => old_user_id})
User.update_all({:updated_at => Time.now}, {:id => [old_user_id, user.id]})
User.update_all({:updated_at => Time.now.utc}, {:id => [old_user_id, user.id]})
end
if User.find(old_user_id).pseudonyms.empty? && migrate
old_user.move_to_user(user)

View File

@ -205,7 +205,7 @@ class Quiz < ActiveRecord::Base
self.context_module_tag.confirm_valid_module_requirements
end
if !self.graded? && (@old_assignment_id || self.last_assignment_id)
Assignment.update_all({:workflow_state => 'deleted', :updated_at => Time.now}, {:id => [@old_assignment_id, self.last_assignment_id].compact, :submission_types => 'online_quiz'})
Assignment.update_all({:workflow_state => 'deleted', :updated_at => Time.now.utc}, {:id => [@old_assignment_id, self.last_assignment_id].compact, :submission_types => 'online_quiz'})
self.quiz_submissions.each { |q| q.submission.try(:destroy); q.submission = nil; q.save }
ContentTag.delete_for(Assignment.find(@old_assignment_id)) if @old_assignment_id
ContentTag.delete_for(Assignment.find(self.last_assignment_id)) if self.last_assignment_id

View File

@ -41,7 +41,7 @@ class QuizQuestion < ActiveRecord::Base
protected :infer_defaults
def update_quiz
Quiz.update_all({:last_edited_at => Time.now}, {:id => self.quiz_id})
Quiz.update_all({:last_edited_at => Time.now.utc}, {:id => self.quiz_id})
end
def question_data=(data)

View File

@ -88,7 +88,7 @@ class Rubric < ActiveRecord::Base
alias_method :destroy!, :destroy
def destroy
RubricAssociation.update_all({:bookmarked => false, :updated_at => Time.now}, {:rubric_id => self.id})
RubricAssociation.update_all({:bookmarked => false, :updated_at => Time.now.utc}, {:rubric_id => self.id})
self.workflow_state = 'deleted'
self.save
end
@ -104,7 +104,7 @@ class Rubric < ActiveRecord::Base
# a rubric_association are 'grading' and 'bookmark'. Confusing,
# I know.
def destroy_for(context)
RubricAssociation.update_all({:bookmarked => false, :updated_at => Time.now}, {:rubric_id => self.id, :context_id => context.id, :context_type => context.class.to_s})
RubricAssociation.update_all({:bookmarked => false, :updated_at => Time.now.utc}, {:rubric_id => self.id, :context_id => context.id, :context_type => context.class.to_s})
if RubricAssociation.scoped(:conditions => {:rubric_id => self.id, :bookmarked => true}).count == 0
self.destroy
end

View File

@ -265,7 +265,7 @@ class StreamItem < ActiveRecord::Base
# the teacher's comment even if it is farther down.
# touch all the users to invalidate the cache
User.update_all({:updated_at => Time.now}, {:id => user_ids})
User.update_all({:updated_at => Time.now.utc}, {:id => user_ids})
return [res]
end
@ -299,7 +299,7 @@ class StreamItem < ActiveRecord::Base
unless user_ids.empty?
# touch all the users to invalidate the cache
User.update_all({:updated_at => Time.now}, {:id => user_ids.to_a})
User.update_all({:updated_at => Time.now.utc}, {:id => user_ids.to_a})
end
count

View File

@ -153,7 +153,7 @@ class ActiveRecord::Base
def touch_context
return if (@@skip_touch_context ||= false || @skip_touch_context ||= false)
if self.respond_to?(:context_type) && self.respond_to?(:context_id) && self.context_type && self.context_id
self.context_type.constantize.update_all({ :updated_at => Time.now }, { :id => self.context_id })
self.context_type.constantize.update_all({ :updated_at => Time.now.utc }, { :id => self.context_id })
end
rescue
ErrorReport.log_exception(:touch_context, $!)
@ -161,7 +161,7 @@ class ActiveRecord::Base
def touch_user
if self.respond_to?(:user_id) && self.user_id
User.update_all({ :updated_at => Time.now }, { :id => self.user_id })
User.update_all({ :updated_at => Time.now.utc }, { :id => self.user_id })
User.invalidate_cache(self.user_id)
end
true

View File

@ -41,9 +41,9 @@ class GradeCalculator
calculate_final_score(user_id, submissions)
end
Course.update_all({:updated_at => Time.now}, {:id => @course.id})
Course.update_all({:updated_at => Time.now.utc}, {:id => @course.id})
if !@current_updates.empty? || !@final_updates.empty?
query = "updated_at=#{Enrollment.connection.quote(Time.now.utc.to_s(:db))}"
query = "updated_at=#{Enrollment.sanitize(Time.now.utc)}"
query += ", computed_current_score=CASE #{@current_updates.join(" ")} ELSE computed_current_score END" unless @current_updates.empty?
query += ", computed_final_score=CASE #{@final_updates.join(" ")} ELSE computed_final_score END" unless @final_updates.empty?
Enrollment.update_all(query, {:user_id => @user_ids, :course_id => @course.id})

View File

@ -202,7 +202,7 @@ module SIS
Enrollment.update_all({:sis_batch_id => @batch.id}, {:id => enrollments_to_update_sis_batch_ids}) if @batch && !enrollments_to_update_sis_batch_ids.empty?
# We batch these up at the end because we don't want to keep touching the same course over and over,
# and to avoid hitting other callbacks for the course (especially broadcast_policy)
Course.update_all({:updated_at => Time.now}, {:id => courses_to_touch_ids.to_a}) unless courses_to_touch_ids.empty?
Course.update_all({:updated_at => Time.now.utc}, {:id => courses_to_touch_ids.to_a}) unless courses_to_touch_ids.empty?
# We batch these up at the end because normally a user would get several enrollments, and there's no reason
# to update their account associations on each one.
if incrementally_update_account_associations_user_ids.length < 10
@ -217,7 +217,7 @@ module SIS
end
User.update_account_associations(update_account_association_user_ids.to_a,
:account_chain_cache => account_chain_cache)
User.update_all({:updated_at => Time.now}, {:id => users_to_touch_ids.to_a}) unless users_to_touch_ids.empty?
User.update_all({:updated_at => Time.now.utc}, {:id => users_to_touch_ids.to_a}) unless users_to_touch_ids.empty?
logger.debug("Enrollments with batch operations took #{Time.now - start} seconds")
end

View File

@ -29,7 +29,7 @@ class SummaryMessageConsolidator
cc_ids = CommunicationChannel.ids_with_pending_delayed_messages
cc_ids.each do |cc_id|
dm_ids = DelayedMessage.ids_for_messages_with_communication_channel_id(cc_id)
DelayedMessage.update_all({ :batched_at => Time.now, :workflow_state => 'sent', :updated_at => Time.now },
DelayedMessage.update_all({ :batched_at => Time.now.utc, :workflow_state => 'sent', :updated_at => Time.now.utc },
{ :id => dm_ids })
DelayedMessage.send_later(:summarize, dm_ids)

View File

@ -163,7 +163,7 @@ class UnzipAttachment
FileInContext.queue_files_to_delete(false)
FileInContext.destroy_queued_files
Attachment.send_later(:submit_to_scribd, @attachments.map(&:id))
Course.update_all({:updated_at => Time.now}, {:id => @course.id})
Course.update_all({:updated_at => Time.now.utc}, {:id => @course.id})
update_progress(1.0)
end

View File

@ -21,16 +21,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../api_spec_helper')
describe SubmissionsApiController, :type => :integration do
def submit_homework(assignment, student, opts = {:body => "test!"})
@submit_homework_time ||= 0
@submit_homework_time ||= Time.zone.at(0)
@submit_homework_time += 1.hour
sub = assignment.find_or_create_submission(student)
if sub.versions.size == 1
Version.update_all({:created_at => Time.at(@submit_homework_time)}, {:id => sub.versions.first.id})
Version.update_all({:created_at => @submit_homework_time}, {:id => sub.versions.first.id})
end
sub.workflow_state = 'submitted'
yield(sub) if block_given?
sub.with_versioning(:explicit => true) do
update_with_protected_attributes!(sub, { :submitted_at => Time.at(@submit_homework_time), :created_at => Time.at(@submit_homework_time) }.merge(opts))
update_with_protected_attributes!(sub, { :submitted_at => @submit_homework_time, :created_at => @submit_homework_time }.merge(opts))
end
sub.versions(true).each { |v| Version.update_all({ :created_at => v.model.created_at }, { :id => v.id }) }
sub

View File

@ -121,7 +121,7 @@ describe WebConference do
# second one doesn't trigger another create call
conference.craft_url(@user).should match(/\Ahttp:\/\/bbb\.instructure\.com\/bigbluebutton\/api\/join/)
WebConference.update_all({:updated_at => Time.now - 1.day}, {:id => conference.id})
WebConference.update_all({:updated_at => 1.day.ago}, {:id => conference.id})
conference.reload
conference.craft_url(@user).should match(/\Ahttp:\/\/bbb\.instructure\.com\/bigbluebutton\/api\/join/)