Skip to content

Commit

Permalink
Minimize specs in SpecsBuilder
Browse files Browse the repository at this point in the history
This is what rubygems.org does to de-dupe strings in the generated marshal, which can make the resulting document much smaller and more efficient for clients to load
  • Loading branch information
segiddins authored and olleolleolle committed Jul 7, 2024
1 parent 29e2603 commit 111d304
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 0 additions & 5 deletions lib/gemstash/db/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ def reindex
update(indexed: true)
end

# This converts to the format used by /private/specs.4.8.gz
def to_spec
[rubygem.name, Gem::Version.new(number), platform]
end

def self.slug(params)
version = params[:version]
platform = params[:platform]
Expand Down
18 changes: 16 additions & 2 deletions lib/gemstash/specs_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,25 @@ def fetch_from_storage
end

def fetch_versions
@versions = Gemstash::DB::Version.for_spec_collection(prerelease: @prerelease, latest: @latest).map(&:to_spec)
@versions = Gemstash::DB::Version.for_spec_collection(prerelease: @prerelease, latest: @latest)
end

def marshal
@marshal ||= Marshal.dump(@versions)
@marshal ||= Marshal.dump(minimize_specs(@versions))
end

def minimize_specs(data)
names = Hash.new {|h, k| h[k] = k }
versions = Hash.new {|h, k| h[k] = Gem::Version.new(k) }
platforms = Hash.new {|h, k| h[k] = k }

data.map do |version|
[
names[version.rubygem.name],
versions[version.number],
platforms[version.platform]
]
end
end

def gzip
Expand Down

0 comments on commit 111d304

Please sign in to comment.