Skip to content

Commit 6321a66

Browse files
committed
Repo key never changes
1 parent a402902 commit 6321a66

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

packages/database/src/core/Repo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const INTERRUPT_REASON = 'repo_interrupt';
5454
* A connection to a single data repository.
5555
*/
5656
export class Repo {
57+
/** Key for uniquely identifying this repo, used in RepoManager */
58+
readonly key: string;
59+
5760
dataUpdateCount = 0;
5861
private infoSyncTree_: SyncTree;
5962
private serverSyncTree_: SyncTree;
@@ -174,6 +177,9 @@ export class Repo {
174177
this.server_.unlisten(query, tag);
175178
}
176179
});
180+
181+
// This key is intentionally not updated if RepoInfo is later changed or replaced
182+
this.key = this.repoInfo_.toURLString();
177183
}
178184

179185
/**

packages/database/src/core/RepoManager.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,10 @@ export class RepoManager {
9898
? new EmulatorAdminTokenProvider()
9999
: repo.authTokenProvider;
100100

101-
// Before we modify the repo, get the key used in the repo manager
102-
const oldRepoKey = repo.repoInfo_.toURLString();
103-
104101
// Update the repo in-place
105102
const { repoInfo } = parseRepoInfo(url, nodeAdmin);
106103
repo.repoInfo_ = repoInfo;
107104
repo.authTokenProvider = authTokenProvider;
108-
109-
// Replace the repomanager cache entry
110-
delete this.repos_[repo.app.name][oldRepoKey];
111-
this.repos_[repo.app.name][repoInfo.toURLString()] = repo;
112105
}
113106

114107
/**
@@ -181,13 +174,13 @@ export class RepoManager {
181174
deleteRepo(repo: Repo) {
182175
const appRepos = safeGet(this.repos_, repo.app.name);
183176
// This should never happen...
184-
if (!appRepos || safeGet(appRepos, repo.repoInfo_.toURLString()) !== repo) {
177+
if (!appRepos || safeGet(appRepos, repo.key) !== repo) {
185178
fatal(
186179
`Database ${repo.app.name}(${repo.repoInfo_}) has already been deleted.`
187180
);
188181
}
189182
repo.interrupt();
190-
delete appRepos[repo.repoInfo_.toURLString()];
183+
delete appRepos[repo.key];
191184
}
192185

193186
/**

0 commit comments

Comments
 (0)