Skip to content
Browse files

Memoize load gems.

  • Loading branch information...
1 parent 15074b9 commit 34993a7b2ae822d6adc54b031e3ef3f5bf1a2fd8 @cwninja cwninja committed
Showing with 11 additions and 11 deletions.
  1. +11 −11 lib/geminabox.rb
View
22 lib/geminabox.rb
@@ -1,10 +1,9 @@
require 'rubygems'
-require "digest/md5"
-require "builder"
+require 'digest/md5'
+require 'builder'
require 'sinatra/base'
require 'rubygems/builder'
-require "rubygems/indexer"
-
+require 'rubygems/indexer'
require 'hostess'
class Geminabox < Sinatra::Base
@@ -152,13 +151,14 @@ def file_path
end
def load_gems
- %w(specs prerelease_specs).inject(GemVersionCollection.new){|gems, specs_file_type|
- specs_file_path = File.join(settings.data, "#{specs_file_type}.#{Gem.marshal_version}.gz")
- if File.exists?(specs_file_path)
- gems |= Geminabox::GemVersionCollection.new(Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path))))
- end
- gems
- }
+ @loaded_gems ||=
+ %w(specs prerelease_specs).inject(GemVersionCollection.new){|gems, specs_file_type|
+ specs_file_path = File.join(settings.data, "#{specs_file_type}.#{Gem.marshal_version}.gz")
+ if File.exists?(specs_file_path)
+ gems |= Geminabox::GemVersionCollection.new(Marshal.load(Gem.gunzip(Gem.read_binary(specs_file_path))))
+ end
+ gems
+ }
end
def index_gems(gems)

0 comments on commit 34993a7

Please sign in to comment.
Something went wrong with that request. Please try again.