From 6de67da28099ef1e2cf1596fe458bd2d3d622283 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Thu, 8 May 2014 16:42:16 -0700 Subject: [PATCH] * Refactor iqdb response collection --- Gemfile | 2 +- Gemfile.lock | 3 --- app/controllers/iqdb_queries_controller.rb | 2 +- app/logical/iqdb/download.rb | 2 +- app/logical/iqdb/responses/collection.rb | 3 ++- app/logical/iqdb/server.rb | 9 --------- app/views/iqdb_queries/create_by_url.html.erb | 4 ++-- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 810d3dfe7..9776a34dc 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,6 @@ end group :development do gem 'ruby-prof' - gem 'sql-logging' + # gem 'sql-logging' end diff --git a/Gemfile.lock b/Gemfile.lock index cade865e2..1f37e6340 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -190,8 +190,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) - sql-logging (3.0.8) - rails (> 3.0.0) statistics2 (0.54) term-ansicolor (1.3.0) tins (~> 1.0) @@ -264,7 +262,6 @@ DEPENDENCIES simple_form simplecov sprockets-rails - sql-logging statistics2 term-ansicolor therubyracer diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index ac23a7ace..de0628976 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -24,7 +24,7 @@ protected def create_by_post @post = Post.find(params[:post_id]) - @results = Iqdb::Server.default.similar(@post.id, 3) + @results = Iqdb::Server.default.query(3, @post.preview_file_path) render :layout => false, :action => "create_by_post" end end \ No newline at end of file diff --git a/app/logical/iqdb/download.rb b/app/logical/iqdb/download.rb index 47f4c9c9b..d2f3afa56 100644 --- a/app/logical/iqdb/download.rb +++ b/app/logical/iqdb/download.rb @@ -14,7 +14,7 @@ module Iqdb def find_similar if Danbooru.config.iqdb_hostname_and_port - @matches = Iqdb::Server.new(*Danbooru.config.iqdb_hostname_and_port).query(3, @download.file_path).matches + @matches = Iqdb::Server.default.query(3, @download.file_path).matches end end end diff --git a/app/logical/iqdb/responses/collection.rb b/app/logical/iqdb/responses/collection.rb index f8cd4915a..a5d3fd34d 100644 --- a/app/logical/iqdb/responses/collection.rb +++ b/app/logical/iqdb/responses/collection.rb @@ -2,7 +2,8 @@ module Iqdb module Responses class Collection attr_reader :responses - delegate :each, :empty?, :any?, :to => :matches + include Enumerable + delegate :<=>, :each, :to => :matches def initialize(response_string) @responses = response_string.split(/\n/).map do |string| diff --git a/app/logical/iqdb/server.rb b/app/logical/iqdb/server.rb index 66d832ccf..787cbbf67 100644 --- a/app/logical/iqdb/server.rb +++ b/app/logical/iqdb/server.rb @@ -49,15 +49,6 @@ module Iqdb end end - def similar(post_id, results, flags = FLAG_DISCARD_COMMON_COEFFS) - request do - hex_id = post_id.to_s(16) - socket.puts "sim 0 #{flags} #{results} #{hex_id}" - socket.puts "done" - responses = Responses::Collection.new(socket.read) - end - end - def query(results, filename, flags = FLAG_DISCARD_COMMON_COEFFS) request do socket.puts "query 0 #{flags} #{results} #{filename}" diff --git a/app/views/iqdb_queries/create_by_url.html.erb b/app/views/iqdb_queries/create_by_url.html.erb index ba06a3ff1..5c3d96a41 100644 --- a/app/views/iqdb_queries/create_by_url.html.erb +++ b/app/views/iqdb_queries/create_by_url.html.erb @@ -1,6 +1,6 @@ -<% if @download.matches.any? %> +<% if @download.any? %>

Similar

- <% @download.matches.each do |match| %> + <% @download.each do |match| %> <%= PostPresenter.preview(Post.find(match.post_id)) %> <% end %> <% else %>