File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,17 @@ int main(int argc, char* argv[]) {
2525 easy::HttpWith<easy::PgDep>(argc, argv)
2626 // Handles multiple HTTP requests to `/kv` URL concurrently
2727 .Get("/kv", [](formats::json::Value request_json, const easy::PgDep& dep) {
28- auto key = request_json.As<schemas::KeyRequest>().key; // parser is generated from schema
28+ // JSON parser and serializer are generated from JSON schema by userver
29+ auto key = request_json.As<schemas::KeyRequest>().key;
2930
3031 // Asynchronous execution of the SQL query in transaction. Current thread
3132 // handles other requests while the response from the DB is being received:
3233 auto res = dep.pg().Execute(
33- storages::postgres::ClusterHostType::kSlave, "SELECT value FROM key_value_table WHERE key=$1", key
34+ storages::postgres::ClusterHostType::kSlave,
35+ // Query is converted into a prepared statement. Subsequent requests
36+ // send only parameters in a binary form and meta information is
37+ // discarded on the DB side, significantly saving network bandwith.
38+ "SELECT value FROM key_value_table WHERE key=$1", key
3439 );
3540
3641 schemas::KeyValue response{key, res[0][0].As<std::string>()};
Original file line number Diff line number Diff line change @@ -143,12 +143,17 @@ int main(int argc, char* argv[]) {
143143 easy::HttpWith<easy::PgDep>(argc, argv)
144144 // Handles multiple HTTP requests to `/kv` URL concurrently
145145 .Get("/kv", [](formats::json::Value request_json, const easy::PgDep& dep) {
146- auto key = request_json.As<schemas::KeyRequest>().key; // parser is generated from schema
146+ // JSON parser and serializer are generated from JSON schema by userver
147+ auto key = request_json.As<schemas::KeyRequest>().key;
147148
148149 // Asynchronous execution of the SQL query in transaction. Current thread
149150 // handles other requests while the response from the DB is being received:
150151 auto res = dep.pg().Execute(
151- storages::postgres::ClusterHostType::kSlave, "SELECT value FROM key_value_table WHERE key=$1", key
152+ storages::postgres::ClusterHostType::kSlave,
153+ // Query is converted into a prepared statement. Subsequent requests
154+ // send only parameters in a binary form and meta information is
155+ // discarded on the DB side, significantly saving network bandwith.
156+ "SELECT value FROM key_value_table WHERE key=$1", key
152157 );
153158
154159 schemas::KeyValue response{key, res[0][0].As<std::string>()};
You can’t perform that action at this time.
0 commit comments