PERF: Improve theme stylesheet compilation performance (#12850)

When building the `scss_load_paths`, we were creating a full export of the theme (including uploads), and not cleaning it up. With many uploads, this can be extremely slow (because it downloads every upload from S3), and the lack of cleanup could cause a disk to fill up over time.

This commit updates the ZipExporter to provide a `with_export_dir` API, which takes care of cleanup. It also adds a kwarg which allows exporting only extra_scss fields. This should make things much faster for themes with many uploads.
This commit is contained in:
David Taylor
2021-04-27 14:33:43 +01:00
committed by GitHub
parent 657dff3544
commit 1fd8f6df5f
4 changed files with 40 additions and 21 deletions

View File

@@ -25,11 +25,22 @@ class ThemeStore::ZipExporter
FileUtils.rm_rf(@temp_folder)
end
def export_to_folder
def with_export_dir(**kwargs)
export_to_folder(**kwargs)
yield File.join(@temp_folder, @export_name)
ensure
cleanup!
end
private
def export_to_folder(extra_scss_only: false)
destination_folder = File.join(@temp_folder, @export_name)
FileUtils.mkdir_p(destination_folder)
@theme.theme_fields.each do |field|
next if extra_scss_only && !field.extra_scss_field?
next unless path = field.file_path
# Belt and braces approach here. All the user input should already be
@@ -50,19 +61,16 @@ class ThemeStore::ZipExporter
File.write(path, content)
end
File.write(File.join(destination_folder, "about.json"), JSON.pretty_generate(@theme.generate_metadata_hash))
if !extra_scss_only
File.write(
File.join(destination_folder, "about.json"),
JSON.pretty_generate(@theme.generate_metadata_hash)
)
end
@temp_folder
end
def export_dir
export_to_folder
File.join(@temp_folder, @export_name)
end
private
def export_package
export_to_folder