mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
Previously, the asset-processor javascript was only cached in production. In development, it would be built on-demand using esbuild every time it was needed. Originally this was incredibly fast. But over the years complexity has increased, and it now takes more than a second, even on fast hardware. This commit adds some caching logic, keyed on the filenames/content of all known input files. In production, this will make things slightly more efficient because the cache will be re-used if an up-to-date version already exists. In development, it will be much more efficient, because `esbuild` will only be invoked when changes are made to the asset process source code. A file-based lock is used to ensure multiple processes do not fight with each other to generate the processor simultaneously.
30 lines
933 B
Ruby
30 lines
933 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe QunitController do
|
|
def production_sign_in(user)
|
|
# We need to call sign_in before stubbing the method because SessionController#become
|
|
# checks for the current env when the file is loaded.
|
|
# We need to make sure become is called once before stubbing, or the method
|
|
# wont'be available for future tests if this one runs first.
|
|
sign_in(user) if user
|
|
Rails.env.stubs(:production?).returns(true)
|
|
end
|
|
|
|
it "hides page for regular users in production" do
|
|
production_sign_in(Fabricate(:user))
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(404)
|
|
end
|
|
|
|
it "hides page for anon in production" do
|
|
production_sign_in(nil)
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(404)
|
|
end
|
|
|
|
it "shows page for admin in production" do
|
|
production_sign_in(Fabricate(:admin))
|
|
get "/theme-qunit"
|
|
expect(response.status).to eq(200)
|
|
end
|
|
end
|