apply method

Set<TableUpdate> apply(
  1. Iterable<TableUpdate> input
)

Obtain a set of all tables that might be affected by direct updates in input.

Implementation

Set<TableUpdate> apply(Iterable<TableUpdate> input) {
  // Most users don't have any update rules, and this check is much faster
  // than crawling through all updates.
  if (rules.isEmpty) return input.toSet();

  final pending = List.of(input);
  final seen = <TableUpdate>{};
  while (pending.isNotEmpty) {
    final update = pending.removeLast();
    seen.add(update);

    for (final rule in rules) {
      if (rule is WritePropagation && rule.on.matches(update)) {
        pending.addAll(rule.result.where((u) => !seen.contains(u)));
      }
    }
  }

  return seen;
}