saved searches: add 'last refreshed' column to index page.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class SavedSearch < ApplicationRecord
|
class SavedSearch < ApplicationRecord
|
||||||
REDIS_EXPIRY = 3600
|
REDIS_EXPIRY = 1.hour
|
||||||
QUERY_LIMIT = 1000
|
QUERY_LIMIT = 1000
|
||||||
|
|
||||||
def self.enabled?
|
def self.enabled?
|
||||||
@@ -7,6 +7,8 @@ class SavedSearch < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
concerning :Redis do
|
concerning :Redis do
|
||||||
|
extend Memoist
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ class SavedSearch < ApplicationRecord
|
|||||||
if redis.exists(redis_key)
|
if redis.exists(redis_key)
|
||||||
sub_ids = redis.smembers(redis_key).map(&:to_i)
|
sub_ids = redis.smembers(redis_key).map(&:to_i)
|
||||||
post_ids.merge(sub_ids)
|
post_ids.merge(sub_ids)
|
||||||
redis.expire(redis_key, REDIS_EXPIRY)
|
redis.expire(redis_key, REDIS_EXPIRY.to_i)
|
||||||
else
|
else
|
||||||
PopulateSavedSearchJob.perform_later(query)
|
PopulateSavedSearchJob.perform_later(query)
|
||||||
end
|
end
|
||||||
@@ -32,6 +34,13 @@ class SavedSearch < ApplicationRecord
|
|||||||
post_ids.to_a.sort.last(QUERY_LIMIT)
|
post_ids.to_a.sort.last(QUERY_LIMIT)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def refreshed_at
|
||||||
|
ttl = SavedSearch.redis.ttl("search:#{query}")
|
||||||
|
return nil if ttl < 0
|
||||||
|
(REDIS_EXPIRY.to_i - ttl).seconds.ago
|
||||||
|
end
|
||||||
|
memoize :refreshed_at
|
||||||
end
|
end
|
||||||
|
|
||||||
concerning :Labels do
|
concerning :Labels do
|
||||||
@@ -109,7 +118,7 @@ class SavedSearch < ApplicationRecord
|
|||||||
|
|
||||||
if post_ids.present?
|
if post_ids.present?
|
||||||
redis.sadd(redis_key, post_ids)
|
redis.sadd(redis_key, post_ids)
|
||||||
redis.expire(redis_key, REDIS_EXPIRY)
|
redis.expire(redis_key, REDIS_EXPIRY.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th data-sort="string">Query</th>
|
<th data-sort="string">Query</th>
|
||||||
<th data-sort="string">Labels</th>
|
<th data-sort="string">Labels</th>
|
||||||
|
<th>Last Refreshed</th>
|
||||||
<th class="links"></th>
|
<th class="links"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -31,6 +32,13 @@
|
|||||||
<%= link_to label, posts_path(:tags => "search:#{label}") %>
|
<%= link_to label, posts_path(:tags => "search:#{label}") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<% if ss.refreshed_at.present? %>
|
||||||
|
<%= time_ago_in_words_tagged ss.refreshed_at %>
|
||||||
|
<% else %>
|
||||||
|
><%= SavedSearch::REDIS_EXPIRY.inspect %> ago
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td class="links">
|
<td class="links">
|
||||||
<%= link_to "edit", edit_saved_search_path(ss) %>
|
<%= link_to "edit", edit_saved_search_path(ss) %>
|
||||||
| <%= link_to "delete", saved_search_path(ss), :method => :delete, :remote => true %>
|
| <%= link_to "delete", saved_search_path(ss), :method => :delete, :remote => true %>
|
||||||
|
|||||||
Reference in New Issue
Block a user