Files
ubicloud/clover.rb
Jeremy Evans f6e72e6386 Avoid 4 allocations for every request
Instead of splitting the host, just check it starts with `api.`.
The four allocations come from:

* 1 array allocation
* 3 string allocations (potentially more or less depending on the
  number of `.` in the Host header)
2024-10-24 08:48:04 -07:00

41 lines
640 B
Ruby

# frozen_string_literal: true
require_relative "model"
require "roda"
class Clover < Roda
def self.freeze
# :nocov:
if Config.test?
Sequel::Model.descendants.each(&:finalize_associations)
else
Sequel::Model.freeze_descendants
DB.freeze
end
# :nocov:
super
end
route do |r|
if r.host.start_with?("api.")
r.run CloverApi
end
# To make test and development easier
# :nocov:
unless Config.production?
r.on "api" do
r.run CloverApi
end
end
# :nocov:
r.on "runtime" do
r.run CloverRuntime
end
r.run CloverWeb
end
end