From f109b416a0965e278bb1147d7e3d0e41e89bded4 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 22 Mar 2023 13:37:18 +0000 Subject: [PATCH] add domain index, check uri on screenshots, set workers to system cpu core count --- migrations/117_add_sites_domain_index.rb | 9 +++++++++ puma_config.rb | 3 +-- workers/screenshot_worker.rb | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 migrations/117_add_sites_domain_index.rb diff --git a/migrations/117_add_sites_domain_index.rb b/migrations/117_add_sites_domain_index.rb new file mode 100644 index 00000000..e7103db7 --- /dev/null +++ b/migrations/117_add_sites_domain_index.rb @@ -0,0 +1,9 @@ +Sequel.migration do + up { + DB.add_index :sites, :domain + } + + down { + DB.drop_index :sites, :domain + } + end diff --git a/puma_config.rb b/puma_config.rb index 2bb939dc..62777654 100644 --- a/puma_config.rb +++ b/puma_config.rb @@ -7,8 +7,7 @@ environment 'production' pidfile '/var/run/neocities/neocities.pid' stdout_redirect '/var/log/neocities/neocities.stdout.log', '/var/log/neocities/neocities.stderr.log', true quiet -workers 8 -#workers Facter.value('processors')['count'] +workers Facter.value('processors')['count'] preload_app! on_worker_boot { DB.disconnect } bind 'unix:/var/run/neocities/neocities.sock?backlog=2048' diff --git a/workers/screenshot_worker.rb b/workers/screenshot_worker.rb index 880d3aef..84f2d682 100644 --- a/workers/screenshot_worker.rb +++ b/workers/screenshot_worker.rb @@ -45,7 +45,10 @@ class ScreenshotWorker begin base_image_tmpfile_path = "/tmp/#{SecureRandom.uuid}.png" - File.write base_image_tmpfile_path, HTTP.basic_auth(user: api_user, pass: api_password).get(uri).to_s + + http_resp = HTTP.basic_auth(user: api_user, pass: api_password).get(uri) + BlackBox.new(site, path).check_uri(http_resp.headers['X-URL']) + File.write base_image_tmpfile_path, http_resp.to_s user_screenshots_path = File.join SCREENSHOTS_PATH, Site.sharding_dir(username), username screenshot_path = File.join user_screenshots_path, File.dirname(path_for_screenshot)