From 9cfc4f2a8aa973f3b1f1ba193913e13017b678e4 Mon Sep 17 00:00:00 2001 From: cxh Date: Wed, 26 Nov 2025 09:30:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/record_manager.cpp | 45 ++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/record_manager.cpp b/src/record_manager.cpp index ad9c37b..7217023 100644 --- a/src/record_manager.cpp +++ b/src/record_manager.cpp @@ -6,9 +6,30 @@ #include #include #include +#include #include "logger.hpp" +namespace +{ +std::optional getEarliestRecordMsInternal( + const std::unordered_map>& index_) +{ + int64_t earliest = -1; + + for (auto& kv : index_) + { + for (auto& f : kv.second) + { + if (earliest < 0 || f.start_ms < earliest) earliest = f.start_ms; + } + } + + if (earliest < 0) return std::nullopt; + return earliest; +} +} // namespace + std::shared_ptr g_record_manager = nullptr; extern std::atomic g_running; @@ -125,24 +146,6 @@ bool RecordManager::loadSrsConfig() return true; } -std::optional RecordManager::getEarliestRecordMs() -{ - std::lock_guard lock(index_mutex_); - - int64_t earliest = -1; - - for (auto& kv : index_) - { - for (auto& f : kv.second) - { - if (earliest < 0 || f.start_ms < earliest) earliest = f.start_ms; - } - } - - if (earliest < 0) return std::nullopt; - return earliest; -} - void RecordManager::removeExpiredDays() { namespace fs = std::filesystem; @@ -310,7 +313,11 @@ void RecordManager::startAutoScan(int interval_sec) this->scanAll(); // ======= 新增:打印最早录像时间 + 磁盘使用率 ======= - auto earliestOpt = this->getEarliestRecordMs(); + std::optional earliestOpt; + { + std::lock_guard lock(index_mutex_); + earliestOpt = getEarliestRecordMsInternal(index_); + } if (earliestOpt.has_value()) { std::string tReadable = RecordManager::toReadable(earliestOpt.value());