work on saved searches embedded in user profiles
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -55,6 +55,7 @@ gem 'responders'
|
|||||||
gem 'highline'
|
gem 'highline'
|
||||||
gem 'dtext_rb', :git => "https://github.com/r888888888/dtext_rb.git", :require => "dtext"
|
gem 'dtext_rb', :git => "https://github.com/r888888888/dtext_rb.git", :require => "dtext"
|
||||||
gem 'google-api-client'
|
gem 'google-api-client'
|
||||||
|
gem 'cityhash'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ GEM
|
|||||||
capistrano3-unicorn (0.2.1)
|
capistrano3-unicorn (0.2.1)
|
||||||
capistrano (~> 3.1, >= 3.1.0)
|
capistrano (~> 3.1, >= 3.1.0)
|
||||||
chronic (0.10.2)
|
chronic (0.10.2)
|
||||||
|
cityhash (0.8.1)
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
coffee-rails (4.1.0)
|
coffee-rails (4.1.0)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
@@ -416,6 +417,7 @@ DEPENDENCIES
|
|||||||
capistrano-rails
|
capistrano-rails
|
||||||
capistrano-rbenv
|
capistrano-rbenv
|
||||||
capistrano3-unicorn
|
capistrano3-unicorn
|
||||||
|
cityhash
|
||||||
coffee-rails
|
coffee-rails
|
||||||
coinbase
|
coinbase
|
||||||
daemons
|
daemons
|
||||||
|
|||||||
@@ -81,4 +81,8 @@ class Cache
|
|||||||
def self.sanitize(key)
|
def self.sanitize(key)
|
||||||
key.gsub(/\W/) {|x| "%#{x.ord}"}.slice(0, 230)
|
key.gsub(/\W/) {|x| "%#{x.ord}"}.slice(0, 230)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.hash(string)
|
||||||
|
CityHash.hash64(string).to_s(36)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
class SavedSearch < ActiveRecord::Base
|
class SavedSearch < ActiveRecord::Base
|
||||||
|
UNCATEGORIZED_NAME = "Uncategorized"
|
||||||
|
|
||||||
module ListbooruMethods
|
module ListbooruMethods
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
@@ -79,22 +81,32 @@ class SavedSearch < ActiveRecord::Base
|
|||||||
def self.post_ids(user_id, name = nil)
|
def self.post_ids(user_id, name = nil)
|
||||||
return [] unless Danbooru.config.listbooru_enabled?
|
return [] unless Danbooru.config.listbooru_enabled?
|
||||||
|
|
||||||
params = {
|
if name
|
||||||
"key" => Danbooru.config.listbooru_auth_key,
|
hash_name = Cache.hash(name)
|
||||||
"user_id" => user_id,
|
else
|
||||||
"name" => name
|
hash_name = nil
|
||||||
}
|
end
|
||||||
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
|
|
||||||
uri.query = URI.encode_www_form(params)
|
|
||||||
|
|
||||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
body = Cache.fetch("ss-pids-#{user_id}-#{hash_name}", 60) do
|
||||||
resp = http.request_get(uri.request_uri)
|
params = {
|
||||||
if resp.is_a?(Net::HTTPSuccess)
|
"key" => Danbooru.config.listbooru_auth_key,
|
||||||
resp.body.scan(/\d+/).map(&:to_i)
|
"user_id" => user_id,
|
||||||
else
|
"name" => name
|
||||||
raise "HTTP error code: #{resp.code} #{resp.message}"
|
}
|
||||||
|
uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
|
||||||
|
uri.query = URI.encode_www_form(params)
|
||||||
|
|
||||||
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||||
|
resp = http.request_get(uri.request_uri)
|
||||||
|
if resp.is_a?(Net::HTTPSuccess)
|
||||||
|
resp.body
|
||||||
|
else
|
||||||
|
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
body.scan(/\d+/).map(&:to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize
|
def normalize
|
||||||
|
|||||||
@@ -788,6 +788,12 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module SavedSearchMethods
|
||||||
|
def unique_saved_search_categories
|
||||||
|
[SavedSearch::UNCATEGORIZED_NAME] + saved_searches.pluck(:category).reject {|x| x.blank?}.uniq
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
include BanMethods
|
include BanMethods
|
||||||
include NameMethods
|
include NameMethods
|
||||||
include PasswordMethods
|
include PasswordMethods
|
||||||
@@ -803,6 +809,7 @@ class User < ActiveRecord::Base
|
|||||||
include CountMethods
|
include CountMethods
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include StatisticsMethods
|
include StatisticsMethods
|
||||||
|
include SavedSearchMethods
|
||||||
|
|
||||||
def initialize_default_image_size
|
def initialize_default_image_size
|
||||||
self.default_image_size = "large"
|
self.default_image_size = "large"
|
||||||
|
|||||||
@@ -39,6 +39,26 @@ class UserPresenter
|
|||||||
permissions.join(", ")
|
permissions.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def posts_for_saved_search_category(category)
|
||||||
|
if category == SavedSearch::UNCATEGORIZED_NAME
|
||||||
|
ids = SavedSearch.post_ids(CurrentUser.user.id)
|
||||||
|
else
|
||||||
|
ids = SavedSearch.post_ids(CurrentUser.user.id, category)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ids.any?
|
||||||
|
arel = Post.where("id in (?)", id.map(&:to_i)).order("id desc").limit(10)
|
||||||
|
|
||||||
|
if CurrentUser.user.hide_deleted_posts?
|
||||||
|
arel = arel.undeleted
|
||||||
|
end
|
||||||
|
|
||||||
|
arel
|
||||||
|
else
|
||||||
|
Post.where("false")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def posts_for_subscription(subscription)
|
def posts_for_subscription(subscription)
|
||||||
arel = Post.where("id in (?)", subscription.post_id_array.map(&:to_i)).order("id desc").limit(6)
|
arel = Post.where("id in (?)", subscription.post_id_array.map(&:to_i)).order("id desc").limit(6)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<% if category.present? %>
|
<% if category.present? %>
|
||||||
<%= link_to_if SavedSearch.posts_search_available?, category.tr("_", " "), posts_path(:tags => "search:#{category}") %>
|
<%= link_to_if SavedSearch.posts_search_available?, category.tr("_", " "), posts_path(:tags => "search:#{category}") %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to_if SavedSearch.posts_search_available?, "Uncategorized", posts_path(:tags => "search:all") %>
|
<%= link_to_if SavedSearch.posts_search_available?, SavedSearch::UNCATEGORIZED_NAME, posts_path(:tags => "search:all") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</h2>
|
</h2>
|
||||||
<table class="striped" width="100%">
|
<table class="striped" width="100%">
|
||||||
|
|||||||
Reference in New Issue
Block a user