Skip to content

Commit

Permalink
try using this->databaseId() in android
Browse files Browse the repository at this point in the history
  • Loading branch information
milaGGL committed May 18, 2023
1 parent b65cffd commit 158986f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion firestore/src/android/firestore_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ FirestoreInternal::FirestoreInternal(App* app, const char* database_id) {
FIREBASE_ASSERT(app != nullptr);
if (!Initialize(app)) return;
app_ = app;
database_name_ = database_id;

Env env = GetEnv();
Local<Object> platform_app(env.get(), app_->GetPlatformApp());
Expand Down
9 changes: 5 additions & 4 deletions firestore/src/android/firestore_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <unordered_set>

#include "Firestore/core/src/model/database_id.h"
#include "app/src/cleanup_notifier.h"
#include "app/src/future_manager.h"
#include "app/src/include/firebase/app.h"
Expand Down Expand Up @@ -136,8 +137,6 @@ class FirestoreInternal {
ListenerRegistrationInternal* registration);
void ClearListeners();

const std::string& database_name() const { return database_name_; }

// Bundles
Future<LoadBundleTaskProgress> LoadBundle(const std::string& bundle);
Future<LoadBundleTaskProgress> LoadBundle(
Expand Down Expand Up @@ -167,6 +166,10 @@ class FirestoreInternal {
firestore_public_ = firestore_public;
}

const model::DatabaseId& database_id() const {
return this->database_id();
}

Firestore* firestore_public() { return firestore_public_; }
const Firestore* firestore_public() const { return firestore_public_; }

Expand Down Expand Up @@ -214,8 +217,6 @@ class FirestoreInternal {
std::unique_ptr<PromiseFactory<AsyncFn>> promises_;

CleanupNotifier cleanup_;

std::string database_name_;
};

// Holds a "weak reference" to a `FirestoreInternal` object.
Expand Down
8 changes: 4 additions & 4 deletions firestore/src/common/firestore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Firestore* Firestore::CreateFirestore(App* app,

MutexLock lock(*g_firestores_lock);

const char* database_id = internal->database_name().c_str();
const char* database_id = internal->database_id().database_id().c_str();
Firestore* from_cache =
FindFirestoreInCache(app, database_id, init_result_out);
SIMPLE_HARD_ASSERT(from_cache == nullptr,
Expand All @@ -200,7 +200,7 @@ Firestore* Firestore::AddFirestoreToCache(Firestore* firestore,
}

FirestoreMap::key_type key =
MakeKey(firestore->app(), firestore->internal_->database_name());
MakeKey(firestore->app(), firestore->internal_->database_id().database_id());
FirestoreCache()->emplace(key, firestore);
return firestore;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ void Firestore::DeleteInternal() {
// Force cleanup to happen first.
internal_->cleanup().CleanupAll();
// Store the database id before deleting the firestore instance.
const std::string database_id = internal_->database_name();
const std::string database_id = internal_->database_id().database_id();
delete internal_;
internal_ = nullptr;
// If a Firestore is explicitly deleted, remove it from our cache.
Expand Down Expand Up @@ -381,7 +381,7 @@ Future<void> Firestore::EnableNetwork() {

Future<void> Firestore::Terminate() {
if (!internal_) return FailedFuture<void>();
FirestoreMap::key_type key = MakeKey(app(), internal_->database_name());
FirestoreMap::key_type key = MakeKey(app(), internal_->database_id().database_id());

FirestoreCache()->erase(key);
return internal_->Terminate();
Expand Down
3 changes: 1 addition & 2 deletions firestore/src/main/firestore_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ FirestoreInternal::FirestoreInternal(
std::move(auth_credentials),
std::move(app_check_credentials))),
transaction_executor_(absl::ShareUniquePtr(Executor::CreateConcurrent(
"com.google.firebase.firestore.transaction", /*threads=*/5))),
database_name_(database_id) {
"com.google.firebase.firestore.transaction", /*threads=*/5))) {
ApplyDefaultSettings();

#if FIREBASE_PLATFORM_ANDROID
Expand Down
3 changes: 0 additions & 3 deletions firestore/src/main/firestore_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ class FirestoreInternal {
return firestore_core_->database_id();
}

const std::string& database_name() const { return database_name_; }

// Bundles
Future<LoadBundleTaskProgress> LoadBundle(const std::string& bundle);
Future<LoadBundleTaskProgress> LoadBundle(
Expand Down Expand Up @@ -187,7 +185,6 @@ class FirestoreInternal {
std::unordered_set<ListenerRegistrationInternal*> listeners_;

std::shared_ptr<util::Executor> transaction_executor_;
std::string database_name_;
};

} // namespace firestore
Expand Down

0 comments on commit 158986f

Please sign in to comment.