lib/lnd/tool/store/htlc_event.rb in lnd-tool-0.2.0 vs lib/lnd/tool/store/htlc_event.rb in lnd-tool-0.3.0
- old
+ new
@@ -78,9 +78,34 @@
bind << limit
end
convert(db.query(query, bind))
end
+ # Get record count.
+ # @return [Integer] record count.
+ def count
+ db.get_first_value('SELECT count(*) FROM HtlcEvent').to_i
+ end
+
+ # Pruning record up to +max+.
+ # @param [Integer] max Maximum number of records for this entity.
+ # @return [Integer] pruning count
+ def prune_up_to(max)
+ pruning_count = count - max
+ return 0 if pruning_count <= 0
+
+ query = 'DELETE FROM HtlcEvent ORDER BY created_datetime ASC LIMIT ?'
+ db.execute(query, [pruning_count])
+ pruning_count
+ end
+
+ # Pruning record prior to +Time+.
+ # @param [Time] time
+ def prune_prior_to(time)
+ query = 'DELETE FROM HtlcEvent WHERE timestamp_ns < ?'
+ db.execute(query, [time.to_i * 1_000_000_000])
+ end
+
private
def convert(recode_sets)
recode_sets.lazy.map do |result|
forward_event = result[6] ? Routerrpc::ForwardEvent.decode_json(result[6]) : nil