smarr / ReBenchDB

ReBenchDB records benchmark results and provides customizable reporting to track and analyze run-time performance of software programs.
MIT License
13 stars 6 forks source link

Use prepared queries where possible, and avoid races on query objects #122

Closed smarr closed 2 years ago

smarr commented 2 years ago

Previously, we used a list of queries in the Database class, which encodes parameters. Though, this is inherently racy, not knowing exactly what the database driver does.

The problem is that multiple clients triggering the same query with different data, may change the query object.

Much of this PR avoids this by not using a big list of query objects. It also moves the queries closer to the code where they are used. Given the size of the file, this seems better. Part of the change is also to change the type of the query method to require a query object, to prefer the use of named queries. This may be useful for the database to "prepare" queries. But it also gives a name to the queries, to possibly avoid duplication of queries in the future.

For queries used in multiple places, we keep using the query list though.

Other Minor Changes

smarr commented 2 years ago

The change in https://github.com/smarr/ReBenchDB/pull/122/commits/e8998b01ac4cd4dad634a5afeb39623288543cf3 should address the second item of #121 and the other changes around QueryConfig objects should hopefully address the first.