Copilot commented on code in PR #1985:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1985#discussion_r2175004653
##########
extensions/windows-event-log/wel/WindowsEventLog.cpp:
##########
@@ -42,6 +42,18 @@ std::string getEventTimestampStr(uint64_t event_timestamp) {
}
} // namespace
+std::optional<std::string> EventDataCache::get(EVT_FORMAT_MESSAGE_FLAGS field,
const std::string& key) {
+ std::lock_guard<std::mutex> lock{mutex_};
+ const auto it = cache_.find(std::make_tuple(field, key));
+ if (it != cache_.end() && it->second.expiry >
std::chrono::system_clock::now()) { return it->second.value; }
Review Comment:
Expired entries are never removed from the cache, which may lead to
unbounded memory growth over time. Consider erasing stale items when detected
to keep cache size in check.
```suggestion
if (it != cache_.end()) {
if (it->second.expiry > std::chrono::system_clock::now()) {
return it->second.value;
} else {
cache_.erase(it); // Remove expired entry
}
}
```
##########
extensions/windows-event-log/wel/WindowsEventLog.h:
##########
@@ -41,6 +41,15 @@
#include "pugixml.hpp"
#include "utils/expected.h"
+template<>
+struct std::hash<std::tuple<EVT_FORMAT_MESSAGE_FLAGS, std::string>> {
Review Comment:
[nitpick] Specializing `std::hash` for `std::tuple<EVT_FORMAT_MESSAGE_FLAGS,
std::string>` in the `std` namespace can lead to undefined behavior. Consider
defining a custom hash functor and passing it to the `unordered_map` instead of
injecting into `std`.
```suggestion
struct TupleHash {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]