From e3c2bf08e6ea8af3c81d89d5b05d241e3d81da6f Mon Sep 17 00:00:00 2001 From: rhymes Date: Tue, 25 Jun 2019 14:42:01 +0200 Subject: [PATCH] Deduplicate history items (#3279) --- app/javascript/history/history.jsx | 9 +-------- app/models/page_view.rb | 5 ++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/javascript/history/history.jsx b/app/javascript/history/history.jsx index 4096e2837..dc091cb00 100644 --- a/app/javascript/history/history.jsx +++ b/app/javascript/history/history.jsx @@ -83,14 +83,7 @@ export class History extends Component { } index.search(query, filters).then(content => { - // add new items to the bottom - const allItems = items; - const itemsIds = items.map(i => i.objectID); - content.hits.forEach(item => { - if (!itemsIds.includes(item.objectID)) { - allItems.push(item); - } - }); + const allItems = [...items, ...content.hits]; this.setState({ query, diff --git a/app/models/page_view.rb b/app/models/page_view.rb index deb027b80..0c39b419d 100644 --- a/app/models/page_view.rb +++ b/app/models/page_view.rb @@ -5,7 +5,7 @@ class PageView < ApplicationRecord belongs_to :article algoliasearch index_name: "UserHistory", per_environment: true, if: :belongs_to_pro_user? do - attributes :referrer, :time_tracked_in_seconds, :user_agent, :article_tags + attributes :referrer, :user_agent, :article_tags attribute(:article_title) { article.title } attribute(:article_path) { article.path } @@ -38,6 +38,9 @@ class PageView < ApplicationRecord attributesForFaceting ["filterOnly(viewable_by)"] + attributeForDistinct :article_path + distinct true + customRanking ["desc(visited_at_timestamp)"] end