loadMetadatas method

  1. @override
Future<List<Metadata?>> loadMetadatas(
  1. List<String> pubKeys
)
override

Implementation

@override
Future<List<Metadata?>> loadMetadatas(List<String> pubKeys) async {
  await dbRdy;
  final metadataBox = _objectBox.store.box<DbMetadata>();
  final existingMetadatas = metadataBox
      .query(DbMetadata_.pubKey.oneOf(pubKeys))
      .order(DbMetadata_.updatedAt, flags: Order.descending)
      .build()
      .find();

  // Create a map for quick lookup
  final metadataMap = <String, Metadata>{};
  for (final dbMetadata in existingMetadatas) {
    // Only keep the first (most recent) entry per pubKey
    if (!metadataMap.containsKey(dbMetadata.pubKey)) {
      metadataMap[dbMetadata.pubKey] = dbMetadata.toNdk();
    }
  }

  // Return list in the same order as input, with null for not found
  return pubKeys.map((pubKey) => metadataMap[pubKey]).toList();
}