| 24 | #include "flow/actorcompiler.h" // This must be the last #include. |
| 25 | |
| 26 | int32_t Cursor::prune(std::map<int64_t, Reference<Cursor>>& cursors, bool pruneAll) { |
| 27 | time_t now = time(nullptr); |
| 28 | int32_t pruned = 0; |
| 29 | std::vector<Reference<Cursor>> to_be_pruned; |
| 30 | |
| 31 | try { |
| 32 | for (auto it = cursors.begin(); it != cursors.end();) { |
| 33 | if (it->second && (pruneAll || now >= it->second->expiry)) { |
| 34 | to_be_pruned.push_back(it->second); |
| 35 | } |
| 36 | ++it; |
| 37 | } |
| 38 | |
| 39 | for (const auto& i : to_be_pruned) { |
| 40 | (void)pluck(i); |
| 41 | pruned++; |
| 42 | } |
| 43 | } catch (Error& e) { |
| 44 | TraceEvent(SevError, "BD_cursor_prune_failed").error(e); |
| 45 | // Ignoring error just to keep the code consistent with previous behaviour. |
| 46 | // Cursor design could be made lot better than this. |
| 47 | } |
| 48 | |
| 49 | return pruned; |
| 50 | } |
| 51 | |
| 52 | void Cursor::pluck(Reference<Cursor> cursor) { |
| 53 | if (cursor) { |