Skip to content

Commit

Permalink
Update Crystal and frameworks (#4020)
Browse files Browse the repository at this point in the history
* Update Crystal and frameworks

* Generate Date header using HTTP.format_time

Not only it is more idiomatic, but faster as well:

Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT") 689.84k (  1.45µs) (± 1.35%)  242 B/op   1.37× slower
                    HTTP.format_time(Time.now) 941.75k (  1.06µs) (± 1.83%)  242 B/op        fastest

* Remove unnecessary X-Powered-By: Kemal
  • Loading branch information
vlazar authored and michaelhixson committed Sep 1, 2018
1 parent 87c778d commit b20ac7b
Show file tree
Hide file tree
Showing 23 changed files with 95 additions and 72 deletions.
2 changes: 1 addition & 1 deletion frameworks/Crystal/amber/amber.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM crystallang/crystal:0.24.1
FROM crystallang/crystal:0.26.1

WORKDIR /amber
COPY config config
Expand Down
5 changes: 3 additions & 2 deletions frameworks/Crystal/amber/config/initializers/database.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "granite_orm/adapter/pg"
require "granite/adapter/pg"

Granite::ORM.settings.logger = Logger.new(nil)
Granite.settings.logger = Logger.new(nil)
Granite::Adapters << Granite::Adapter::Pg.new({name: "pg", url: ENV["DATABASE_URL"]})
56 changes: 34 additions & 22 deletions frameworks/Crystal/amber/shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,85 @@ version: 1.0
shards:
amber:
github: amberframework/amber
version: 0.6.7
version: 0.9.0

amber_router:
github: amberframework/amber-router
version: 0.2.0

callback:
github: mosop/callback
version: 0.6.3

cli:
github: amberframework/cli
github: mosop/cli
version: 0.7.0

compiled_license:
github: elorest/compiled_license
version: 0.1.3

db:
github: crystal-lang/crystal-db
version: 0.5.0

granite_orm:
github: amberframework/granite-orm
version: 0.8.4
granite:
github: amberframework/granite
version: 0.13.1

inflector:
github: phoffer/inflector.cr
version: 0.1.8

kilt:
github: jeromegn/kilt
version: 0.4.0

micrate:
github: juanedi/micrate
liquid:
github: TechMagister/liquid.cr
version: 0.3.0

micrate:
github: amberframework/micrate
version: 0.3.3

mysql:
github: crystal-lang/crystal-mysql
version: 0.4.0
version: 0.5.0

optarg:
github: mosop/optarg
version: 0.5.8

pg:
github: will/crystal-pg
version: 0.14.1
version: 0.15.0

radix:
github: luislavena/radix
version: 0.3.8
pool:
github: ysbaddaden/pool
version: 0.2.3

redis:
github: stefanwille/crystal-redis
version: 1.9.0
version: 2.0.0

shell-table:
github: jwaldrip/shell-table.cr
version: 0.9.2
github: luckyframework/shell-table.cr
commit: 078a04ea58ead5203bb435a3b5fff448ddabaeea

slang:
github: jeromegn/slang
version: 1.7.1

spinner:
github: askn/spinner
version: 0.1.1

sqlite3:
github: crystal-lang/crystal-sqlite3
version: 0.9.0
version: 0.10.0

string_inflection:
github: mosop/string_inflection
version: 0.2.1

teeplate:
github: amberframework/teeplate
version: 0.5.0
github: mosop/teeplate
version: 0.6.1

8 changes: 4 additions & 4 deletions frameworks/Crystal/amber/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ targets:
dependencies:
amber:
github: amberframework/amber
version: 0.6.7
version: 0.9.0

granite_orm:
github: amberframework/granite-orm
version: 0.8.4
granite:
github: amberframework/granite
version: 0.13.1
10 changes: 5 additions & 5 deletions frameworks/Crystal/amber/src/controllers/benchmark_controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BenchmarkController < Amber::Controller::Base
before_action do
all do
response.headers["Server"] = "Amber"
response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
response.headers["Date"] = HTTP.format_time(Time.now)
end
end

Expand All @@ -26,7 +26,7 @@ class BenchmarkController < Amber::Controller::Base
response.content_type = JSON
results = {} of Symbol => Int32
if world = World.find rand(1..ID_MAXIMUM)
results = {id: world.id, randomNumber: world.randomNumber}
results = {id: world.id, randomNumber: world.randomnumber}
end
results.to_json
end
Expand All @@ -39,7 +39,7 @@ class BenchmarkController < Amber::Controller::Base

results = (1..queries).map do
if world = World.find rand(1..ID_MAXIMUM)
{id: world.id, randomNumber: world.randomNumber}
{id: world.id, randomNumber: world.randomnumber}
end
end

Expand All @@ -54,9 +54,9 @@ class BenchmarkController < Amber::Controller::Base

results = (1..queries).map do
if world = World.find rand(1..ID_MAXIMUM)
world.randomNumber = rand(1..ID_MAXIMUM)
world.randomnumber = rand(1..ID_MAXIMUM)
world.save
{id: world.id, randomNumber: world.randomNumber}
{id: world.id, randomNumber: world.randomnumber}
end
end

Expand Down
4 changes: 2 additions & 2 deletions frameworks/Crystal/amber/src/models/fortune.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "granite_orm/adapter/pg"
require "granite/adapter/pg"

class Fortune < Granite::ORM::Base
class Fortune < Granite::Base
adapter pg

table_name fortune
Expand Down
6 changes: 3 additions & 3 deletions frameworks/Crystal/amber/src/models/world.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "granite_orm/adapter/pg"
require "granite/adapter/pg"

class World < Granite::ORM::Base
class World < Granite::Base
adapter pg

table_name world
primary id : Int32
field randomNumber : Int32
field randomnumber : Int32
end
2 changes: 1 addition & 1 deletion frameworks/Crystal/crystal/crystal-radix.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM crystallang/crystal:0.24.1
FROM crystallang/crystal:0.26.1

WORKDIR /crystal
COPY views views
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Crystal/crystal/crystal.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM crystallang/crystal:0.24.1
FROM crystallang/crystal:0.26.1

WORKDIR /crystal
COPY views views
Expand Down
6 changes: 3 additions & 3 deletions frameworks/Crystal/crystal/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require "ecr"
APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?initial_pool_size=256&max_pool_size=256&max_idle_pool_size=256")
ID_MAXIMUM = 10_000

server = HTTP::Server.new("0.0.0.0", 8080) do |context|
server = HTTP::Server.new do |context|
response = context.response
request = context.request

response.headers["Server"] = "Crystal"
response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
response.headers["Date"] = HTTP.format_time(Time.now)

case request.path
when "/json"
Expand Down Expand Up @@ -95,4 +95,4 @@ private def sanitized_query_count(request)
queries.clamp(1..500)
end

server.listen(reuse_port: true)
server.listen("0.0.0.0", 8080, reuse_port: true)
6 changes: 3 additions & 3 deletions frameworks/Crystal/crystal/server_radix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ tree.add "/updates", updates_handler
APPDB = DB.open("postgres://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world")
ID_MAXIMUM = 10_000

server = HTTP::Server.new("0.0.0.0", 8080) do |context|
server = HTTP::Server.new do |context|
request = context.request
response = context.response
response.headers["Server"] = "Crystal"
response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
response.headers["Date"] = HTTP.format_time(Time.now)

result = tree.find(request.path)

Expand Down Expand Up @@ -134,4 +134,4 @@ private def sanitized_query_count(request)
queries.clamp(1..500)
end

server.listen(reuse_port: true)
server.listen("0.0.0.0", 8080, reuse_port: true)
2 changes: 1 addition & 1 deletion frameworks/Crystal/crystal/shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ shards:

pg:
github: will/crystal-pg
version: 0.14.1
version: 0.15.0

radix:
github: luislavena/radix
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Crystal/crystal/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license: MIT
dependencies:
pg:
github: will/crystal-pg
version: 0.14.1
version: 0.15.0

radix:
github: luislavena/radix
Expand Down
4 changes: 2 additions & 2 deletions frameworks/Crystal/h2o.cr/h2o.cr.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ RUN apt update \
&& apt install -yqq libh2o-evloop-dev libwslay-dev libyaml-0-2 libevent-dev libpcre3-dev \
gcc wget git libssl-dev libuv1-dev ca-certificates --no-install-recommends

RUN wget -q https://github.com/crystal-lang/crystal/releases/download/0.24.2/crystal-0.24.2-1-linux-x86_64.tar.gz \
&& tar --strip-components=1 -xzf crystal-0.24.2-1-linux-x86_64.tar.gz -C /usr/ \
RUN wget -q https://github.com/crystal-lang/crystal/releases/download/0.26.1/crystal-0.26.1-1-linux-x86_64.tar.gz \
&& tar --strip-components=1 -xzf crystal-0.26.1-1-linux-x86_64.tar.gz -C /usr/ \
&& rm -f *.tar.gz

WORKDIR /crystal
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Crystal/h2o.cr/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 0.0.1

license: MIT

crystal: 0.24.2
crystal: 0.26.1

dependencies:
h2o:
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Crystal/kemal/kemal.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM crystallang/crystal:0.24.1
FROM crystallang/crystal:0.26.1

WORKDIR /kemal
COPY views views
Expand Down
5 changes: 3 additions & 2 deletions frameworks/Crystal/kemal/server-postgres.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end

before_all do |env|
env.response.headers["Server"] = "Kemal"
env.response.headers["Date"] = Time.utc_now.to_s("%a, %d %b %Y %H:%M:%S GMT")
env.response.headers["Date"] = HTTP.format_time(Time.now)
end

#
Expand Down Expand Up @@ -111,6 +111,7 @@ end
Kemal.config do |cfg|
cfg.serve_static = false
cfg.logging = false
cfg.powered_by_header = false
end

Kemal.run { |cfg| cfg.server.not_nil!.bind(reuse_port: true) }
Kemal.run { |cfg| cfg.server.not_nil!.bind_tcp(cfg.host_binding, cfg.port, reuse_port: true) }
14 changes: 11 additions & 3 deletions frameworks/Crystal/kemal/shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ shards:
github: crystal-lang/crystal-db
version: 0.5.0

exception_page:
github: crystal-loot/exception_page
version: 0.1.1

kemal:
github: kemalcr/kemal
version: 0.22.0
version: 0.24.0

kilt:
github: jeromegn/kilt
version: 0.4.0

pg:
github: will/crystal-pg
version: 0.14.1
version: 0.15.0

pool:
github: ysbaddaden/pool
version: 0.2.3

radix:
github: luislavena/radix
version: 0.3.8

redis:
github: stefanwille/crystal-redis
version: 1.9.0
version: 2.0.0

6 changes: 3 additions & 3 deletions frameworks/Crystal/kemal/shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ license: MIT
dependencies:
pg:
github: will/crystal-pg
version: 0.14.1
version: 0.15.0
kemal:
github: kemalcr/kemal
version: 0.22.0
version: 0.24.0
redis:
github: stefanwille/crystal-redis
version: 1.9.0
version: 2.0.0
Loading

0 comments on commit b20ac7b

Please sign in to comment.