Extract the database connection handling from the server

Previously, one of the first things that happened when responding to a request
was a database connection was made, even when serving the CSS. This is
unnecessary, so move the database connection handling in to the controller.

Also, to allow for separating it out from the assets, separate the assets out
from the parts of the controller that require a database connection.
This commit is contained in:
Christopher Baines 2019-06-06 20:39:06 +01:00
parent 544dc1558f
commit aad2c9d9e8
4 changed files with 39 additions and 31 deletions

View file

@ -23,22 +23,18 @@
#:use-module (web request)
#:use-module (web uri)
#:use-module (fibers web server)
#:use-module (guix-data-service database)
#:use-module (guix-data-service web controller)
#:use-module (guix-data-service web util)
#:export (start-guix-data-service-web-server))
(define (run-controller controller request body)
(with-postgresql-connection
(lambda (conn)
(let-values (((request-components mime-types)
(request->path-components-and-mime-type request)))
(controller request
(cons (request-method request)
request-components)
mime-types
body
conn)))))
(let-values (((request-components mime-types)
(request->path-components-and-mime-type request)))
(controller request
(cons (request-method request)
request-components)
mime-types
body)))
(define (handler request body controller)
(format #t "~a ~a\n"