+(* Server-wide settings.
+ *
+ * These are stored in a single row in the database in the table
+ * 'server_settings'. You must restart the server if you change
+ * this row.
+ *
+ * It's not possible to read these at server start-up time because the
+ * Apache server is still running as 'root' and will not normally be
+ * allowed to access the database. We thus read them at the earliest
+ * opportunity, in a request context, and cache the results.
+ *)
+let server_settings_version =
+ let settings = ref None in
+ let get_settings (dbh : Dbi.connection) =
+ let sth = dbh#prepare "select version from server_settings" in
+ sth#execute [];
+ let s =
+ match sth#fetch1 () with
+ | [ `Int version ] -> version
+ | _ -> assert false in
+ sth#finish ();
+ settings := Some s;
+ s
+ in
+
+ let server_settings_version dbh =
+ let (version) =
+ match !settings with
+ None -> get_settings dbh
+ | Some settings -> settings in
+ version
+ in
+
+ server_settings_version
+