docFields method
One indexed lookup per chunk of ids (doc_id IN (...)), never a table
scan.
Implementation
@override
Future<Map<String, Map<String, Object?>>> docFields(
String table, Iterable<String> docIds) async {
if (_db == null) return {};
final out = <String, Map<String, Object?>>{};
final ids = docIds.toList();
// Stay under SQLite's bound-parameter limit.
const chunkSize = 400;
for (var start = 0; start < ids.length; start += chunkSize) {
final chunk = ids.sublist(start,
start + chunkSize > ids.length ? ids.length : start + chunkSize);
final rows = _open.select(
'SELECT doc_id, field_path, value FROM crdt_records '
'WHERE collection = ? AND is_deleted = 0 AND field_path IS NOT NULL '
'AND doc_id IN (${List.filled(chunk.length, '?').join(', ')})',
[table, ...chunk],
);
for (final r in rows) {
(out[r['doc_id'] as String] ??= {})[r['field_path'] as String] =
jsonDecode(r['value'] as String);
}
}
return out;
}