diff --git a/app/decorators/podcast_episode_decorator.rb b/app/decorators/podcast_episode_decorator.rb index dd15c1c2a..572220695 100644 --- a/app/decorators/podcast_episode_decorator.rb +++ b/app/decorators/podcast_episode_decorator.rb @@ -34,4 +34,8 @@ class PodcastEpisodeDecorator < ApplicationDecorator podcastImageUrl: image_url } end + + def published_at_int + published_at.to_i + end end diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index f0ce6bd4c..b9ff7e601 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -3,9 +3,7 @@ class PodcastEpisode < ApplicationRecord duration_in_seconds ] - include AlgoliaSearch include Searchable - SEARCH_SERIALIZER = Search::PodcastEpisodeSerializer SEARCH_CLASS = Search::FeedContent @@ -14,6 +12,7 @@ class PodcastEpisode < ApplicationRecord delegate :slug, to: :podcast, prefix: true delegate :image_url, to: :podcast, prefix: true delegate :title, to: :podcast, prefix: true + delegate :published, to: :podcast belongs_to :podcast has_many :comments, as: :commentable, inverse_of: :commentable @@ -44,45 +43,10 @@ class PodcastEpisode < ApplicationRecord joins(:podcast).where(podcasts: { creator_id: user.id }) } - algoliasearch per_environment: true do - attribute :id - add_index "searchables", - id: :index_id, - per_environment: true do - attribute :title, :body, :quote, :summary, :subtitle, :website_url, - :published_at, :comments_count, :path, :class_name, - :user_name, :user_username, :published, :comments_blob, - :body_text, :tag_list, :tag_keywords_for_search, - :positive_reactions_count, :search_score - attribute :user do - { name: podcast.name, - username: user_username, - profile_image_90: ProfileImage.new(user).get(width: 90) } - end - searchableAttributes ["unordered(title)", - "body_text", - "tag_list", - "tag_keywords_for_search", - "user_name", - "user_username", - "comments_blob"] - attributesForFaceting [:class_name] - customRanking ["desc(search_score)", "desc(hotness_score)"] - end - end - def search_id "podcast_episode_#{id}" end - def user_username - podcast_slug - end - - def user_name - podcast_title - end - def comments_blob comments.pluck(:body_markdown).join(" ") end @@ -93,22 +57,10 @@ class PodcastEpisode < ApplicationRecord "/#{podcast.slug}/#{slug}" end - def published_at_int - published_at.to_i - end - - def published - true - end - def description ActionView::Base.full_sanitizer.sanitize(body) end - def main_image - nil - end - def profile_image_url image_url || "http://41orchard.com/wp-content/uploads/2011/12/Robot-Chalkboard-Decal.gif" end @@ -117,10 +69,6 @@ class PodcastEpisode < ApplicationRecord ActionView::Base.full_sanitizer.sanitize(processed_html) end - def user - podcast - end - def zero_method 0 end @@ -144,16 +92,8 @@ class PodcastEpisode < ApplicationRecord alias second_user_id nil_method alias third_user_id nil_method - def liquid_tags_used - [] - end - private - def index_id - "podcast_episodes-#{id}" - end - def bust_cache PodcastEpisodes::BustCacheWorker.perform_async(id, path, podcast_slug) end diff --git a/app/serializers/search/podcast_episode_serializer.rb b/app/serializers/search/podcast_episode_serializer.rb index 8857897bd..8490ca232 100644 --- a/app/serializers/search/podcast_episode_serializer.rb +++ b/app/serializers/search/podcast_episode_serializer.rb @@ -5,16 +5,13 @@ module Search attribute :id, &:search_id attributes :body_text, :class_name, :comments_count, :hotness_score, :path, - :positive_reactions_count, :published_at, :quote, + :positive_reactions_count, :published, :published_at, :quote, :reactions_count, :search_score, :subtitle, :summary, :title, :website_url attribute :main_image do |pde| ProfileImage.new(pde.podcast).get(width: 90) end - attribute :published do |pde| - pde.podcast.published - end attribute :slug, &:podcast_slug attribute :tags do |pde| diff --git a/spec/models/podcast_episode_spec.rb b/spec/models/podcast_episode_spec.rb index 1de1103a9..ed1ee8841 100644 --- a/spec/models/podcast_episode_spec.rb +++ b/spec/models/podcast_episode_spec.rb @@ -60,13 +60,6 @@ RSpec.describe PodcastEpisode, type: :model do end end - describe "#index_id" do - it "is equal to articles-ID" do - # NOTE: we shouldn't test private things but cheating a bit for Algolia here - expect(podcast_episode.send(:index_id)).to eq("podcast_episodes-#{podcast_episode.id}") - end - end - describe ".available" do let_it_be(:podcast) { create(:podcast) }