From 1a9440ec3c1669c5e49825dde70b9cbede3f0de0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Oct 2025 15:48:28 +0100 Subject: Fix premature remembering of saved entity ids Don't persist entity ids saved to the DB until the transaction is committed. Prevents the issue where a later DB operation fails, the transaction is rolled back, but we still think the entity has been saved. --- src/ingestor.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ingestor.hpp') diff --git a/src/ingestor.hpp b/src/ingestor.hpp index a20071e..8be7360 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -60,13 +60,15 @@ namespace WebStat { size_t linesParsed = 0; size_t linesDiscarded = 0; size_t linesParked = 0; + mutable std::flat_set existingEntities; using JobLastRunTime = std::chrono::system_clock::time_point; JobLastRunTime lastRunIngestParkedLines; private: static constexpr size_t MAX_NEW_ENTITIES = 6; - void storeEntities(DB::Connection *, std::span>) const; + using NewEntityIds = std::array, MAX_NEW_ENTITIES>; + NewEntityIds storeEntities(DB::Connection *, std::span>) const; using NewEntities = std::array, MAX_NEW_ENTITIES>; template NewEntities newEntities(const std::tuple &) const; void handleCurlOperations(); @@ -75,7 +77,6 @@ namespace WebStat { void jobIngestParkedLine(const std::filesystem::path &, uintmax_t size); using CurlOperations = std::map>; - mutable std::flat_set existingEntities; uint32_t hostnameId; CurlMultiPtr curl; mutable CurlOperations curlOperations; -- cgit v1.2.3