Skip to content

Commit 415178a

Browse files
amabluea-maurice
authored andcommitted
SingleValueListeners that have completed should remove themselves from the list
of registered listeners in the database. PiperOrigin-RevId: 269678254
1 parent 2f35c93 commit 415178a

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

database/src/desktop/database_desktop.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ namespace internal {
4343
Mutex g_database_reference_constructor_mutex; // NOLINT
4444

4545
SingleValueListener::SingleValueListener(DatabaseInternal* database,
46+
const QuerySpec& query_spec,
4647
ReferenceCountedFutureImpl* future,
4748
SafeFutureHandle<DataSnapshot> handle)
48-
: database_(database), future_(future), handle_(handle) {}
49+
: database_(database),
50+
query_spec_(query_spec),
51+
future_(future),
52+
handle_(handle) {}
4953

5054
SingleValueListener::~SingleValueListener() {
5155
database_->RemoveSingleValueListener(this);

database/src/desktop/database_desktop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ typedef int64_t WriteId;
4848

4949
class SingleValueListener : public ValueListener {
5050
public:
51-
SingleValueListener(DatabaseInternal* database,
51+
SingleValueListener(DatabaseInternal* database, const QuerySpec& query_spec,
5252
ReferenceCountedFutureImpl* future,
5353
SafeFutureHandle<DataSnapshot> handle);
5454
// Unregister ourselves from the database.
5555
~SingleValueListener() override;
5656
void OnValueChanged(const DataSnapshot& snapshot) override;
5757
void OnCancelled(const Error& error_code, const char* error_message) override;
58+
const QuerySpec& query_spec() { return query_spec_; }
5859

5960
private:
6061
DatabaseInternal* database_;
62+
QuerySpec query_spec_;
6163
ReferenceCountedFutureImpl* future_;
6264
SafeFutureHandle<DataSnapshot> handle_;
6365
};
@@ -148,6 +150,7 @@ class DatabaseInternal {
148150
return *listener_holder == listener;
149151
});
150152
if (iter != single_value_listeners_.end()) {
153+
repo_.RemoveEventCallback(listener, listener->query_spec());
151154
delete *iter;
152155
single_value_listeners_.erase(iter);
153156
}

database/src/desktop/query_desktop.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Future<DataSnapshot> QueryInternal::GetValue() {
156156
// TODO(b/68878322): Refactor this code to be less brittle, possibly using the
157157
// CleanupNotifier or something like it.
158158
SingleValueListener* single_listener =
159-
new SingleValueListener(database_, query_future(), handle);
159+
new SingleValueListener(database_, query_spec_, query_future(), handle);
160160

161161
// If the database goes away, we need to be able to reach into these blocks
162162
// and clear their single_listener pointer. We can't do that directly, but we

0 commit comments

Comments
 (0)