asset_sync 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62e44f8d9bde08301b849aa0747f87400c01daadbcbe5a052e9d9862a8e3e32f
4
- data.tar.gz: f23f8c1f4cf737a15c0f79d7d4ca94f4800d801c8443ae81d6eb25e0605ad866
3
+ metadata.gz: e7e222d9419b7c2039f3db9a20676ec264eaaa233c9d954fd62a28a56bdf2968
4
+ data.tar.gz: 3fc2471434cd60071d283a59cef97f0ff845c4066161ce8c99b93d08435abe66
5
5
  SHA512:
6
- metadata.gz: 8aa520c8a0e507543986db116f5a3631161d85056e049acbf045fa4f3af6c9b71f7131146c5aa63c5aef5573d0efb25c451c51078d6b439ba476e157577cedb2
7
- data.tar.gz: c507c91d2d928fa8fcd30d3413fa2f6b8b04faeb6dd21ac6831bddf36a5905823f446f507ad08fc182092ff4983cb0403221854051e7b8ba3c3a70f517231f84
6
+ metadata.gz: fd001d4c15476c0b72b10bf8630a08a52910189b583b000adb0b3ceea925cd66f6e0bf94e72a2774213e5133be03c4dfc6e8d9d58ba8d4b8f0b5df393a52b853
7
+ data.tar.gz: 8115434ee5a0d37f09350fa3e4c1e4402b47635c7b04eff6f638df65c08edca9a5ba76f05c7993ea09cc57ecd2447b16b002d85b5cb6fc0cc6d24199caddbef6
@@ -18,6 +18,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [2.11.0] - 2020-03-13
22
+
23
+ ### Added
24
+
25
+ - Add option `remote_file_list_cache_file_path` to skip scanning remote
26
+ (https://github.com/AssetSync/asset_sync/pull/400)
27
+
28
+
21
29
  ## [2.10.0] - 2020-02-26
22
30
 
23
31
  ### Added
@@ -954,7 +962,8 @@ Changes:
954
962
  * Merge branch 'sinatra'
955
963
 
956
964
 
957
- [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.10.0...HEAD
965
+ [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.11.0...HEAD
966
+ [2.11.0]: https://github.com/AssetSync/asset_sync/compare/v2.10.0...v2.11.0
958
967
  [2.10.0]: https://github.com/AssetSync/asset_sync/compare/v2.9.1...v2.10.0
959
968
  [2.9.1]: https://github.com/AssetSync/asset_sync/compare/v2.9.0...v2.9.1
960
969
  [2.9.0]: https://github.com/AssetSync/asset_sync/compare/v2.8.2...v2.9.0
data/README.md CHANGED
@@ -248,6 +248,9 @@ AssetSync.configure do |config|
248
248
  # Number of threads when concurrent_uploads is enabled
249
249
  # config.concurrent_uploads_max_threads = 10
250
250
  #
251
+ # Path to cache file to skip scanning remote
252
+ # config.remote_file_list_cache_file_path = './.asset_sync_remote_file_list_cache.json'
253
+ #
251
254
  # Fail silently. Useful for environments such as Heroku
252
255
  # config.fail_silently = true
253
256
  #
@@ -346,6 +349,7 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
346
349
  * **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
347
350
  * **concurrent_uploads**: (`true, false`) when enabled, will upload the files in different Threads, this greatly improves the upload speed. **default:** `'false'`
348
351
  * **concurrent_uploads_max_threads**: when concurrent_uploads is enabled, this determines the number of threads that will be created. **default:** `10`
352
+ * **remote_file_list_cache_file_path**: if present, use this path to cache remote file list to skip scanning remote **default:** `nil`
349
353
  * **enabled**: (`true, false`) when false, will disable asset sync. **default:** `'true'` (enabled)
350
354
  * **ignored\_files**: an array of files to ignore e.g. `['ignore_me.js', %r(ignore_some/\d{32}\.css)]` Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy **default**: `[]`
351
355
  * **cache\_asset\_regexps**: an array of files to add cache headers e.g. `['cache_me.js', %r(cache_some\.\d{8}\.css)]` Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally **default**: `[]`
@@ -28,6 +28,7 @@ module AssetSync
28
28
  attr_accessor :include_manifest
29
29
  attr_accessor :concurrent_uploads
30
30
  attr_accessor :concurrent_uploads_max_threads
31
+ attr_accessor :remote_file_list_cache_file_path
31
32
 
32
33
  # FOG configuration
33
34
  attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
@@ -88,6 +89,7 @@ module AssetSync
88
89
  self.include_manifest = false
89
90
  self.concurrent_uploads = false
90
91
  self.concurrent_uploads_max_threads = 10
92
+ self.remote_file_list_cache_file_path = nil
91
93
  @additional_local_file_paths_procs = []
92
94
 
93
95
  load_yml! if defined?(::Rails) && yml_exists?
@@ -225,6 +227,7 @@ module AssetSync
225
227
  self.include_manifest = yml['include_manifest'] if yml.has_key?("include_manifest")
226
228
  self.concurrent_uploads = yml['concurrent_uploads'] if yml.has_key?('concurrent_uploads')
227
229
  self.concurrent_uploads_max_threads = yml['concurrent_uploads_max_threads'] if yml.has_key?('concurrent_uploads_max_threads')
230
+ self.remote_file_list_cache_file_path = yml['remote_file_list_cache_file_path'] if yml.has_key?('remote_file_list_cache_file_path')
228
231
 
229
232
  self.azure_storage_account_name = yml['azure_storage_account_name'] if yml.has_key?("azure_storage_account_name")
230
233
  self.azure_storage_access_key = yml['azure_storage_access_key'] if yml.has_key?("azure_storage_access_key")
@@ -43,6 +43,7 @@ module AssetSync
43
43
  config.manifest = (ENV['ASSET_SYNC_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_MANIFEST')
44
44
  config.include_manifest = (ENV['ASSET_SYNC_INCLUDE_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_INCLUDE_MANIFEST')
45
45
  config.concurrent_uploads = (ENV['ASSET_SYNC_CONCURRENT_UPLOADS'] == 'true') if ENV.has_key?('ASSET_SYNC_CONCURRENT_UPLOADS')
46
+ config.remote_file_list_cache_file_path = ENV['ASSET_SYNC_REMOTE_FILE_LIST_CACHE_FILE_PATH'] if ENV.has_key?('ASSET_SYNC_REMOTE_FILE_LIST_CACHE_FILE_PATH')
46
47
  end
47
48
 
48
49
  config.prefix = ENV['ASSET_SYNC_PREFIX'] if ENV.has_key?('ASSET_SYNC_PREFIX')
@@ -37,6 +37,10 @@ module AssetSync
37
37
  self.config.public_path
38
38
  end
39
39
 
40
+ def remote_file_list_cache_file_path
41
+ self.config.remote_file_list_cache_file_path
42
+ end
43
+
40
44
  def ignored_files
41
45
  expand_file_names(self.config.ignored_files)
42
46
  end
@@ -58,6 +62,32 @@ module AssetSync
58
62
  (get_local_files + config.additional_local_file_paths).uniq
59
63
  end
60
64
 
65
+ def remote_files
66
+ return [] if ignore_existing_remote_files?
67
+ return @remote_files if @remote_files
68
+
69
+ if remote_file_list_cache_file_path && File.file?(remote_file_list_cache_file_path)
70
+ begin
71
+ content = File.read(remote_file_list_cache_file_path)
72
+ return @remote_files = JSON.parse(content)
73
+ rescue JSON::ParserError
74
+ warn "Failed to parse #{remote_file_list_cache_file_path} as json"
75
+ end
76
+ end
77
+
78
+ @remote_files = get_remote_files
79
+ end
80
+
81
+ def update_remote_file_list_cache(local_files_to_upload)
82
+ return unless remote_file_list_cache_file_path
83
+ return if ignore_existing_remote_files?
84
+
85
+ File.open(self.remote_file_list_cache_file_path, 'w') do |file|
86
+ uploaded = local_files_to_upload + remote_files
87
+ file.write(uploaded.to_json)
88
+ end
89
+ end
90
+
61
91
  def always_upload_files
62
92
  expand_file_names(self.config.always_upload) + get_manifest_path
63
93
  end
@@ -243,8 +273,6 @@ module AssetSync
243
273
  end
244
274
 
245
275
  def upload_files
246
- # get a fresh list of remote files
247
- remote_files = ignore_existing_remote_files? ? [] : get_remote_files
248
276
  # fixes: https://github.com/rumblelabs/asset_sync/issues/19
249
277
  local_files_to_upload = local_files - ignored_files - remote_files + always_upload_files
250
278
  local_files_to_upload = (local_files_to_upload + get_non_fingerprinted(local_files_to_upload)).uniq
@@ -279,6 +307,8 @@ module AssetSync
279
307
  data = cdn.post_invalidation(self.config.cdn_distribution_id, files_to_invalidate)
280
308
  log "Invalidation id: #{data.body["Id"]}"
281
309
  end
310
+
311
+ update_remote_file_list_cache(local_files_to_upload)
282
312
  end
283
313
 
284
314
  def sync
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssetSync
4
- VERSION = "2.10.0"
4
+ VERSION = "2.11.0"
5
5
  end
@@ -66,6 +66,9 @@ if defined?(AssetSync)
66
66
  # Upload files concurrently
67
67
  # config.concurrent_uploads = false
68
68
  #
69
+ # Path to cache file to skip scanning remote
70
+ # config.remote_file_list_cache_file_path = './.asset_sync_remote_file_list_cache.json'
71
+ #
69
72
  # Fail silently. Useful for environments such as Heroku
70
73
  # config.fail_silently = true
71
74
  #
@@ -87,6 +87,54 @@ describe AssetSync::Storage do
87
87
  storage.upload_files
88
88
  end
89
89
 
90
+ it 'should allow remote_file_list_cache_file_path configuration' do
91
+ file_path = './foo.json'
92
+ @config.remote_file_list_cache_file_path = file_path
93
+ storage = AssetSync::Storage.new(@config)
94
+
95
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
96
+ File.write(file_path, @remote_files.to_json)
97
+ expect(storage).not_to receive(:get_remote_files)
98
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
99
+
100
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
101
+ expect(storage).to receive(:upload_file).with(file)
102
+ end
103
+
104
+ expect(storage).not_to receive(:warn)
105
+ storage.upload_files
106
+
107
+ # update remote_file_list_cache corretly
108
+ updated = JSON.parse(File.read(file_path))
109
+ expect(updated.sort.uniq).to eq (@remote_files + @local_files + storage.always_upload_files).sort.uniq
110
+
111
+ File.delete(file_path)
112
+ end
113
+
114
+ it 'should work with broken cache' do
115
+ file_path = './foo.json'
116
+ @config.remote_file_list_cache_file_path = file_path
117
+
118
+ storage = AssetSync::Storage.new(@config)
119
+
120
+ File.write(file_path, 'some non-json text file content')
121
+
122
+ allow(storage).to receive(:get_local_files).and_return(@local_files)
123
+ allow(storage).to receive(:get_remote_files).and_return(@remote_files)
124
+ allow(File).to receive(:file?).and_return(true) # Pretend they all exist
125
+
126
+ (@local_files - @remote_files + storage.always_upload_files).each do |file|
127
+ expect(storage).to receive(:upload_file).with(file)
128
+ end
129
+
130
+ # when broken, warning message should be prompted
131
+ expect(storage).to receive(:warn)
132
+
133
+ storage.upload_files
134
+
135
+ File.delete(file_path)
136
+ end
137
+
90
138
  it 'should upload updated non-fingerprinted files' do
91
139
  @local_files = [
92
140
  'public/image.png',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-02-26 00:00:00.000000000 Z
14
+ date: 2020-03-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core