Skip to content

Commit 0e9082b

Browse files
committed
query - no need to use an explicit TX with find/findFirst() because they use a visitor
1 parent ade55f4 commit 0e9082b

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

objectbox/lib/src/native/query/query.dart

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import '../../modelinfo/entity_definition.dart';
1313
import '../../modelinfo/modelproperty.dart';
1414
import '../../modelinfo/modelrelation.dart';
1515
import '../../store.dart';
16-
import '../../transaction.dart';
1716
import '../bindings/bindings.dart';
1817
import '../bindings/data_visitor.dart';
1918
import '../bindings/helpers.dart';
@@ -735,18 +734,16 @@ class Query<T> {
735734
}
736735
}
737736

738-
/// Finds Objects matching the query and returns the first result or null
739-
/// if there are no results. Note: [offset] and [limit] are respected, if set.
737+
/// Finds the first object matching the query. Returns null if there are no
738+
/// results. Note: [offset] and [limit] are respected, if set.
740739
T? findFirst() {
741740
T? result;
742741
final visitor = dataVisitor((Pointer<Uint8> data, int size) {
743742
result = _entity.objectFromFB(
744743
_store, InternalStoreAccess.reader(_store).access(data, size));
745744
return false; // we only want to visit the first element
746745
});
747-
_store.runInTransaction(TxMode.read, () {
748-
checkObx(C.query_visit(_ptr, visitor, nullptr));
749-
});
746+
checkObx(C.query_visit(_ptr, visitor, nullptr));
750747
reachabilityFence(this);
751748
return result;
752749
}
@@ -769,8 +766,7 @@ class Query<T> {
769766
List<T> find() {
770767
final result = <T>[];
771768
final collector = objectCollector(result, _store, _entity);
772-
_store.runInTransaction(
773-
TxMode.read, () => checkObx(C.query_visit(_ptr, collector, nullptr)));
769+
checkObx(C.query_visit(_ptr, collector, nullptr));
774770
reachabilityFence(this);
775771
return result;
776772
}

0 commit comments

Comments
 (0)