Fix amendment voting persistence:

An incorrect SQL query could cause the server to improperly
configure its voting state after a restart; typically, this
would manifest as an apparent failure to store a vote which
the administrator of the server had configured.

This commit fixes the broken SQL and ensures that amendment
votes are properly reloaded post-restart and closes #4220.
This commit is contained in:
Howard Hinnant
2022-07-05 16:56:54 -04:00
committed by Nik Bougalis
parent 8266d9d598
commit b0b44d32bd

View File

@@ -254,7 +254,10 @@ readAmendments(
soci::transaction tr(session);
std::string sql =
"SELECT AmendmentHash, AmendmentName, Veto FROM FeatureVotes";
"SELECT AmendmentHash, AmendmentName, Veto FROM "
"( SELECT AmendmentHash, AmendmentName, Veto, RANK() OVER "
"( PARTITION BY AmendmentHash ORDER BY ROWID DESC ) "
"as rnk FROM FeatureVotes ) WHERE rnk = 1";
// SOCI requires boost::optional (not std::optional) as parameters.
boost::optional<std::string> amendment_hash;
boost::optional<std::string> amendment_name;