getByIds method
Loads all instances of T whose primary key is in the set at
ReadByIdsOperation.itemIds.
This could in theory be a version of getItems with a specific IdsIn
filter, but that would complicate the extra caching logic handled by this
method. The source of that complication is the difference between a
"where in" filter and a generic filter. The difference is that with
a "where in" filter, you know when you are still missing objects and can
forward that request onto the next source just to fill in the gaps.
However, with a generic filter, you do not know whether or not you are
missing any records and thus cannot be clever with the a request to the
next source.
This method makes use of that extra knowledge afforded by a "where in" filter to load records efficiently; which is what would be lost, or at least greatly complicated, if this method was rolled into calling getItems with an equivalent filter.
Implementation
@override
Future<ReadListResult<T>> getByIds(ReadByIdsOperation<T> operation) async {
operation.details.assertEmpty('LocalSource<$T>.getByIds');
final items = await _itemsCache.multiRead(operation.itemIds);
final foundItemIds = items.keys.toSet();
final missingItemIds = operation.itemIds.difference(foundItemIds);
return ReadListResult<T>.fromMap(
items,
operation.details,
missingItemIds,
);
}