Skip to content

Commit 52e397e

Browse files
committed
Added support for storing more than 1000 files using S3. Improved performance when using S3.
1 parent f5e1f17 commit 52e397e

File tree

1 file changed

+14
-3
lines changed
  • lib/git-media/transport

1 file changed

+14
-3
lines changed

lib/git-media/transport/s3.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ def put_file(sha, from_file)
4545
end
4646

4747
def get_unpushed(files)
48-
keys = @s3.list_bucket(@bucket).map { |f| f[:key] }
48+
# Using a set instead of a list improves performance a lot
49+
# since it reduces the complexity from O(n^2) to O(n)
50+
keys = Set.new()
51+
52+
# Apparently the list_bucket method only returns the first 1000 elements
53+
# This method however will continue to give back results until all elements
54+
# have been listed
55+
@s3.incrementally_list_bucket(@bucket) { |contents|
56+
contents[:contents].each { |element|
57+
keys.add (element[:key])
58+
}
59+
}
60+
4961
files.select do |f|
5062
!keys.include?(f)
5163
end
5264
end
53-
5465
end
5566
end
56-
end
67+
end

0 commit comments

Comments
 (0)