Skip to content
Snippets Groups Projects
Commit 00a8ab61 authored by Nick Thomas's avatar Nick Thomas
Browse files

Lazily load LiteBlob#data

Some operations, notably `Repository#delete_blob`, don't need access to the
blob content. Loading it from disc in these cases is unnecessary.

This commit lazily loads the content on first access and memoizes it. If it
is never accessed, it will never be loaded.

This should reduce disc access significantly for commits that delete lots of
files.
parent bb927920
No related branches found
No related tags found
1 merge request!25Lazily load LiteBlob#data
Loading
Loading
@@ -7,18 +7,21 @@ module Elasticsearch
include Linguist::BlobHelper
include Elasticsearch::Git::EncoderHelper
 
attr_accessor :id, :name, :path, :data, :size, :mode, :commit_id
attr_accessor :id, :name, :path, :size, :mode, :commit_id
attr_writer :data
 
def initialize(repo, raw_blob_hash)
@id = raw_blob_hash[:oid]
blob = repo.lookup(@id)
@blob = repo.lookup(@id)
 
@mode = raw_blob_hash[:mode].to_s(8)
@size = blob.size
@size = @blob.size
@path = encode!(raw_blob_hash[:path])
@name = @path.split('/').last
@data = encode!(blob.content)
end
def data
@data ||= encode!(@blob.content)
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment