recentFor method

  1. @override
Future<List<MetricSample>> recentFor(
  1. NodeId nodeId, {
  2. int limit = 100,
  3. DateTime? since,
})
override

Returns recent samples for nodeId, newest first, up to limit.

since bounds the window: only samples captured at or after it are returned. Applied before limit, so "the last hour" is the last hour and not the newest limit samples that happen to fall in it.

Implementation

@override
Future<List<MetricSample>> recentFor(
  NodeId nodeId, {
  int limit = 100,
  DateTime? since,
}) async {
  final list = _samples[nodeId.value] ?? const [];
  final window = since == null
      ? list.reversed
      : list.reversed.where((s) => !s.at.isBefore(since));
  return window.take(limit).toList();
}