Skip to content

Commit

Permalink
+ TODOs, + Small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
floere committed Aug 7, 2013
1 parent 4ee9365 commit 2d38da0
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 67 deletions.
2 changes: 1 addition & 1 deletion server/lib/picky/backends/prepared/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def dump hash
#
# Yields an id string and a token.
#
# TODO Think about the comma - what if you have commas in the id?
# TODO Think about the comma - what if you have commas in the id? Use CSV?
#
def retrieve
id = nil
Expand Down
11 changes: 6 additions & 5 deletions server/lib/picky/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Category
attr_accessor :exact,
:partial
attr_reader :name,
:prepared,
:backend
attr_writer :source

Expand Down Expand Up @@ -71,10 +70,6 @@ def configure_indexes_from options

@exact = exact_for weights, similarity, options
@partial = partial_for @exact, partial, weights, options

# TODO Is creating a prepared always necessary here? Not really.
#
@prepared = Backends::Prepared::Text.new prepared_index_path
end
# Since the options hash might contain options that do not exist,
# we should warn people if they use the wrong options.
Expand Down Expand Up @@ -116,6 +111,12 @@ def partial_for exact, partial_options, weights, options
end
end

# Lazily create a prepared index proxy.
#
def prepared
@prepared ||= Backends::Prepared::Text.new prepared_index_path
end

# Indexes and loads the category.
#
def reindex
Expand Down
2 changes: 0 additions & 2 deletions server/lib/picky/index_indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def unblock_source
#
# Parameter is a method name to use on the key (e.g. :to_i, :to_s, :strip, :split).
#
# TODO Rename id_format?
#
def key_format key_format = nil
key_format ? (@key_format = key_format) : @key_format
end
Expand Down
2 changes: 1 addition & 1 deletion server/lib/picky/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def clear_indexes
# Registers an index with the indexes.
#
def register index
# TODO DO not store duplicate indexes.
# TODO Do not store duplicate indexes.
#
# self.indexes.delete_if { |existing| existing.name == index.name }
self.indexes << index
Expand Down
4 changes: 2 additions & 2 deletions server/lib/picky/query/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def symbolize!
#
# TODO Do we really need to set the predefined categories on the token?
#
def predefined_categories mapper
@predefined_categories || extract_predefined(mapper)
def predefined_categories mapper = nil
@predefined_categories || mapper && extract_predefined(mapper)
end
def extract_predefined mapper
user_qualified = categorize_with mapper, @qualifiers
Expand Down
107 changes: 54 additions & 53 deletions server/spec/functional/pool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,59 @@

# TODO Why are both versions almost equally fast?
#
context 'without pool' do
# TODO Reinstate after checking assumption about Ruby 2.
#
# it 'runs the GC more' do
# # Quickly check if the pool is removed.
# #
# fail 'object pool still installed' if Picky::Query::Token.respond_to? :release_all
#
# try = search
# query = 'abracadabra mirgel'
# gc_runs_of do
# amount.times { try.search query }
# end.should >= 10
# end
it 'is less (?) performant' do
try = search
query = 'abracadabra mirgel'
performance_of do
amount.times { try.search query }
end.should >= 0.15
end
end
context 'with pool' do
before(:each) do
Picky::Pool.install
end
after(:each) do
# Reload since installing the Pool taints the classes.
#
Picky::Loader.load_framework
end
it 'runs the GC less' do
# Quickly check that the pool is added.
#
fail 'object pool not installed' unless Picky::Query::Token.respond_to? :release_all

try = search
query = 'abracadabra mirgel'
gc_runs_of do
amount.times do
try.search query
Picky::Pool.release_all
end
end.should <= 1 # Definitely less GC runs.
end
it 'is more (?) performant' do
try = search
query = 'abracadabra mirgel'
performance_of do
amount.times { try.search query }
end.should <= 0.2
end
end
# context 'without pool' do
# it 'runs the GC more' do
# # Quickly check if the pool is removed.
# #
# fail 'object pool still installed' if Picky::Query::Token.respond_to? :release_all
#
# try = search
# query = 'abracadabra mirgel'
# gc_runs_of do
# amount.times { try.search query }
# end.should >= 10
# end
# it 'is less (?) performant' do
# try = search
# query = 'abracadabra mirgel'
# performance_of do
# amount.times { try.search query }
# end.should <= 0.15
# end
# end
# context 'with pool' do
# before(:each) do
# Picky::Pool.install
# end
# after(:each) do
# # Reload since installing the Pool taints the classes.
# #
# Picky::Loader.load_framework
# end
# it 'runs the GC less' do
# # Quickly check that the pool is added.
# #
# fail 'object pool not installed' unless Picky::Query::Token.respond_to? :release_all
#
# try = search
# query = 'abracadabra mirgel'
# gc_runs_of do
# amount.times do |i|
# try.search query
# Picky::Pool.release_all if i % 5 == 0
# end
# end.should <= 1 # Definitely less GC runs.
# end
# it 'is more (?) performant' do
# try = search
# query = 'abracadabra it whatever mirgel'
# performance_of do
# amount.times do |i|
# try.search query
# Picky::Pool.release_all if i % 5 == 0
# end
# end.should <= 0.2
# end
# end

end
4 changes: 1 addition & 3 deletions server/spec/lib/query/token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

describe 'categorize' do
let(:mapper) do
# TODO Can we remove the index?
#
index = Picky::Index.new :mapper
categories = Picky::Categories.new
@category1 = categories << Picky::Category.new(:category1, index)
Expand Down Expand Up @@ -98,7 +96,7 @@
end
it 'returns a list of tokens with the right categorization' do
token.similar_tokens_for(@category).map do |token|
token.predefined_categories nil # TODO Clean this up.
token.predefined_categories
end.should == [[@category], [@category], [@category]]
end
end
Expand Down

0 comments on commit 2d38da0

Please sign in to comment.