-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
When preparing a query, a function Dialect.t -> string
is passed to Request.create
to compute the query string depending on the database backend. I would expect this function to be called only once to prepare the query, but it is actually called each time the query is used. This is due to Request_cache.find_and_promote
recalculating it each time to lookup its internal hash table of queries.
While not critical in itself, it seems a bit wasteful and can duplicate side effects - in our case we log the prepared queries, so we are getting spammed by this log.
Amongst solutions I could imagine:
- Have a
string Hashtbl.Make(Dialect)
in queries that cache the actual query per dialect. Very simple, but it hurts my feelings a bit to have to lookup a hashtbl every time. - All queries actually already have a unique integer id, it seems to me that indexing the cache by this id would be much simpler and way faster? Currently it has to recompute the query string every time, but also compare the input and output types. But maybe I'm being naive and missing something?
If there is a consensus that this is indeed desirable and on which solution is the best one, I'd be happy to submit a PR.
Metadata
Metadata
Assignees
Labels
No labels