getMany method

  1. @override
Future<Map<String, AtData>> getMany(
  1. List<String> keys
)
override

Bulk fetch — returns the values for every key in keys that is currently present. Keys that are absent are NOT included in the returned map.

Implementation

@override
Future<Map<String, AtData>> getMany(List<String> keys) async {
  if (!getBox().isOpen) {
    throw DataStoreException(
        'Failed to bulk-fetch keys. Hive Keystore is not initialized or opened');
  }
  final box = getBox() as LazyBox;
  final result = <String, AtData>{};
  for (final raw in keys) {
    final lowered = raw.toLowerCase();
    final hiveKey = HiveKeyStoreHelper.prepareKey(lowered);
    if (!box.containsKey(hiveKey)) continue;
    try {
      // A present key always maps to a non-null AtData — the store
      // never persists null. The guard only satisfies the type.
      final value = await box.get(hiveKey);
      if (value != null) {
        value.key = hiveKey;
        result[lowered] = value;
      }
    } on Exception catch (e) {
      logger.severe('HiveAtKeyValueStore getMany exception for "$raw": $e');
      throw DataStoreException('exception in getMany: ${e.toString()}');
    } on HiveError catch (error) {
      logger.severe('HiveAtKeyValueStore getMany error: $error');
      await _restartHiveBox(error);
      throw DataStoreException(error.message);
    }
  }
  return result;
}