Skip to content

Commit 28cf3ef

Browse files
wilhuffa-maurice
authored andcommitted
Use a single, shared executor for running transactions
PiperOrigin-RevId: 312338832
1 parent 34d1aee commit 28cf3ef

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

firestore/src/ios/firestore_ios.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ FirestoreInternal::FirestoreInternal(App* app)
5353
FirestoreInternal::FirestoreInternal(
5454
App* app, std::unique_ptr<CredentialsProvider> credentials)
5555
: app_(NOT_NULL(app)),
56-
firestore_core_(CreateFirestore(app, std::move(credentials))) {
56+
firestore_core_(CreateFirestore(app, std::move(credentials))),
57+
transaction_executor_(absl::ShareUniquePtr(Executor::CreateConcurrent(
58+
"com.google.firebase.firestore.transaction", /*threads=*/5))) {
5759
ApplyDefaultSettings();
5860
}
5961

@@ -130,8 +132,7 @@ Future<void> FirestoreInternal::RunTransaction(TransactionFunction* update) {
130132

131133
Future<void> FirestoreInternal::RunTransaction(
132134
std::function<Error(Transaction&, std::string&)> update) {
133-
auto executor = absl::ShareUniquePtr(Executor::CreateConcurrent(
134-
"com.google.firebase.firestore.transaction", /*threads=*/5));
135+
auto executor = transaction_executor_;
135136
auto promise =
136137
promise_factory_.CreatePromise<void>(AsyncApi::kRunTransaction);
137138

firestore/src/ios/firestore_ios.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class Transaction;
2727
class TransactionFunction;
2828
class WriteBatch;
2929

30+
namespace util {
31+
class Executor;
32+
}
33+
3034
class FirestoreInternal {
3135
public:
3236
// Note: call `set_firestore_public` immediately after construction.
@@ -145,6 +149,8 @@ class FirestoreInternal {
145149
// TODO(b/136119216): revamp this mechanism on both iOS and Android.
146150
std::mutex listeners_mutex_;
147151
std::unordered_set<ListenerRegistrationInternal*> listeners_;
152+
153+
std::shared_ptr<util::Executor> transaction_executor_;
148154
};
149155

150156
} // namespace firestore

0 commit comments

Comments
 (0)