From 83d44401f5671d98a66c47fe029aa63a05ad1c02 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Wed, 2 Sep 2020 12:56:33 -0500 Subject: [PATCH] [deploy] Index Reaction created_at Timestamp (#10142) --- app/serializers/search/reaction_serializer.rb | 2 +- config/elasticsearch/mappings/reactions.json | 3 +++ .../20200415200651_index_reading_list_reactions.rb | 10 +++++----- .../20200901194251_reindex_reading_list_reactions.rb | 11 +++++++++++ ...spec.rb => reindex_reading_list_reactions_spec.rb} | 4 ++-- spec/serializers/search/reaction_serializer_spec.rb | 4 ++-- 6 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 lib/data_update_scripts/20200901194251_reindex_reading_list_reactions.rb rename spec/lib/data_update_scripts/{index_reading_list_reactions_spec.rb => reindex_reading_list_reactions_spec.rb} (73%) diff --git a/app/serializers/search/reaction_serializer.rb b/app/serializers/search/reaction_serializer.rb index a0c6ee115..e86cfe95d 100644 --- a/app/serializers/search/reaction_serializer.rb +++ b/app/serializers/search/reaction_serializer.rb @@ -1,6 +1,6 @@ module Search class ReactionSerializer < ApplicationSerializer - attributes :id, :category, :status, :user_id + attributes :id, :created_at, :category, :status, :user_id attribute :reactable do |reaction| reactable = reaction.reactable diff --git a/config/elasticsearch/mappings/reactions.json b/config/elasticsearch/mappings/reactions.json index 351c60528..89cfe8f0d 100644 --- a/config/elasticsearch/mappings/reactions.json +++ b/config/elasticsearch/mappings/reactions.json @@ -7,6 +7,9 @@ "category": { "type": "keyword" }, + "created_at": { + "type": "date" + }, "last_indexed_at": { "type": "date" }, diff --git a/lib/data_update_scripts/20200415200651_index_reading_list_reactions.rb b/lib/data_update_scripts/20200415200651_index_reading_list_reactions.rb index bf0dacda9..eb8f93f49 100644 --- a/lib/data_update_scripts/20200415200651_index_reading_list_reactions.rb +++ b/lib/data_update_scripts/20200415200651_index_reading_list_reactions.rb @@ -1,11 +1,11 @@ module DataUpdateScripts class IndexReadingListReactions def run - Reaction.readinglist.select(:id).in_batches do |batch| - Search::BulkIndexWorker.set(queue: :default).perform_async( - "Reaction", batch.ids - ) - end + # Reaction.readinglist.select(:id).in_batches do |batch| + # Search::BulkIndexWorker.set(queue: :default).perform_async( + # "Reaction", batch.ids + # ) + # end end end end diff --git a/lib/data_update_scripts/20200901194251_reindex_reading_list_reactions.rb b/lib/data_update_scripts/20200901194251_reindex_reading_list_reactions.rb new file mode 100644 index 000000000..59a7008b8 --- /dev/null +++ b/lib/data_update_scripts/20200901194251_reindex_reading_list_reactions.rb @@ -0,0 +1,11 @@ +module DataUpdateScripts + class ReindexReadingListReactions + def run + Reaction.readinglist.select(:id).in_batches do |batch| + Search::BulkIndexWorker.set(queue: :default).perform_async( + "Reaction", batch.ids + ) + end + end + end +end diff --git a/spec/lib/data_update_scripts/index_reading_list_reactions_spec.rb b/spec/lib/data_update_scripts/reindex_reading_list_reactions_spec.rb similarity index 73% rename from spec/lib/data_update_scripts/index_reading_list_reactions_spec.rb rename to spec/lib/data_update_scripts/reindex_reading_list_reactions_spec.rb index 48acaaf5d..84a622f8a 100644 --- a/spec/lib/data_update_scripts/index_reading_list_reactions_spec.rb +++ b/spec/lib/data_update_scripts/reindex_reading_list_reactions_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" -require Rails.root.join("lib/data_update_scripts/20200415200651_index_reading_list_reactions.rb") +require Rails.root.join("lib/data_update_scripts/20200901194251_reindex_reading_list_reactions.rb") -describe DataUpdateScripts::IndexReadingListReactions, elasticsearch: "Reaction" do +describe DataUpdateScripts::ReindexReadingListReactions, elasticsearch: "Reaction" do it "indexes feed content(articles, comments, podcast episodes) to Elasticsearch" do reactions = create_list(:reaction, 3, category: "readinglist") Sidekiq::Worker.clear_all diff --git a/spec/serializers/search/reaction_serializer_spec.rb b/spec/serializers/search/reaction_serializer_spec.rb index dbfe1582c..a5c22265d 100644 --- a/spec/serializers/search/reaction_serializer_spec.rb +++ b/spec/serializers/search/reaction_serializer_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Search::ReactionSerializer do user_data = Search::NestedUserSerializer.new(user).serializable_hash.dig(:data, :attributes) expect(data_hash.dig(:reactable, :user)).to eq(user_data) expect(data_hash[:reactable].keys).to include(:id, :body_text, :class_name, :path, :tags, :title) - expect(data_hash.keys).to include(:id, :category, :status, :user_id) + expect(data_hash.keys).to include(:id, :created_at, :category, :status, :user_id) end it "serializes a comment reaction" do @@ -21,7 +21,7 @@ RSpec.describe Search::ReactionSerializer do user_data = Search::NestedUserSerializer.new(user).serializable_hash.dig(:data, :attributes) expect(data_hash.dig(:reactable, :user)).to eq(user_data) expect(data_hash[:reactable].keys).to include(:id, :body_text, :class_name, :path, :tags, :title) - expect(data_hash.keys).to include(:id, :category, :status, :user_id) + expect(data_hash.keys).to include(:id, :created_at, :category, :status, :user_id) end it "creates valid json for Elasticsearch" do