Re-materialize views for out of sync discussion topics
fixes ADMIN-689 relates to https://gerrit.instructure.com/#/c/138106/ Test plan - Run and make sure it doesn't error Change-Id: I761f125205ba09f2e96064ffe956c535b8f87fa7 Reviewed-on: https://gerrit.instructure.com/138340 Reviewed-by: Cody Cutrer <cody@instructure.com> Reviewed-by: Steven Burnett <sburnett@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com> Tested-by: Jenkins Product-Review: Mysti Sadler <mysti@instructure.com>
This commit is contained in:
parent
531dd972df
commit
47ed034df5
|
@ -0,0 +1,29 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class FixDiscussionTopicMaterializedViews < ActiveRecord::Migration[5.0]
|
||||
tag :postdeploy
|
||||
|
||||
def up
|
||||
DataFixup::FixDiscussionTopicMaterializedViews.send_later_if_production_enqueue_args(:run,
|
||||
priority: Delayed::LOW_PRIORITY,
|
||||
n_strand: 'long_datafixups')
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Copyright (C) 2018 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module DataFixup
|
||||
class FixDiscussionTopicMaterializedViews
|
||||
def self.run
|
||||
topic_ids = nil
|
||||
Shackles.activate(:slave) do
|
||||
result = ActiveRecord::Base.connection.execute(
|
||||
"with entries as (
|
||||
select count(*) as c, discussion_topic_id
|
||||
from #{DiscussionEntry.quoted_table_name}
|
||||
group by discussion_topic_id
|
||||
) , matview as (
|
||||
select coalesce(array_length(regexp_split_to_array(entry_ids_array, E'\n'), 1) -2,0) as c
|
||||
, discussion_topic_id
|
||||
from #{DiscussionTopic::MaterializedView.quoted_table_name}
|
||||
where generation_started_at < now() - interval '10 minutes'
|
||||
)
|
||||
select entries.discussion_topic_id as topic
|
||||
, entries.c as ent
|
||||
, matview.c as mat
|
||||
from matview,entries
|
||||
where matview.discussion_topic_id=entries.discussion_topic_id
|
||||
and matview.c != entries.c;")
|
||||
|
||||
topic_ids = result.map{|d| d['topic']}
|
||||
end
|
||||
|
||||
Shackles.activate(:master) do
|
||||
DiscussionTopic.where(id: topic_ids).find_each do |dt|
|
||||
DiscussionTopic::MaterializedView.for(dt).update_materialized_view_without_send_later
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue