Skip to content

Commit d9cf32e

Browse files
committed
Remove user from globals cache.
1 parent 37b97be commit d9cf32e

File tree

7 files changed

+23
-35
lines changed

7 files changed

+23
-35
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public LocalStore(Persistence persistence, QueryEngine queryEngine, User initial
156156
this.persistence = persistence;
157157
this.queryEngine = queryEngine;
158158

159+
globalsCache = persistence.getGlobalsCache();
159160
targetCache = persistence.getTargetCache();
160161
bundleCache = persistence.getBundleCache();
161162
targetIdGenerator = TargetIdGenerator.forTargetCache(targetCache.getHighestTargetId());
@@ -171,7 +172,6 @@ public LocalStore(Persistence persistence, QueryEngine queryEngine, User initial
171172

172173
private void initializeUserComponents(User user) {
173174
// TODO(indexing): Add spec tests that test these components change after a user change
174-
globalsCache = persistence.getGlobalsCache(user);
175175
indexManager = persistence.getIndexManager(user);
176176
mutationQueue = persistence.getMutationQueue(user, indexManager);
177177
documentOverlayCache = persistence.getDocumentOverlayCache(user);

firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryPersistence.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class MemoryPersistence extends Persistence {
3131
// tests affecting both the in-memory and SQLite-backed persistence layers. Tests can create a new
3232
// LocalStore wrapping this Persistence instance and this will make the in-memory persistence
3333
// layer behave as if it were actually persisting values.
34-
private final Map<User, MemoryGlobalsCache> userGlobals;
34+
private final MemoryGlobalsCache globalsCache;
3535
private final Map<User, MemoryMutationQueue> mutationQueues;
3636
private final Map<User, MemoryDocumentOverlayCache> overlays;
3737
private final MemoryIndexManager indexManager;
@@ -58,7 +58,7 @@ public static MemoryPersistence createLruGcMemoryPersistence(
5858

5959
/** Use static helpers to instantiate */
6060
private MemoryPersistence() {
61-
userGlobals = new HashMap<>();
61+
globalsCache = new MemoryGlobalsCache();
6262
mutationQueues = new HashMap<>();
6363
indexManager = new MemoryIndexManager();
6464
targetCache = new MemoryTargetCache(this);
@@ -120,13 +120,8 @@ MemoryRemoteDocumentCache getRemoteDocumentCache() {
120120
}
121121

122122
@Override
123-
GlobalsCache getGlobalsCache(User user) {
124-
MemoryGlobalsCache globals = userGlobals.get(user);
125-
if (globals == null) {
126-
globals = new MemoryGlobalsCache();
127-
userGlobals.put(user, globals);
128-
}
129-
return globals;
123+
GlobalsCache getGlobalsCache() {
124+
return globalsCache;
130125
}
131126

132127
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/local/Persistence.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public abstract class Persistence {
8686
/** Creates a RemoteDocumentCache representing the persisted cache of remote documents. */
8787
abstract RemoteDocumentCache getRemoteDocumentCache();
8888

89-
/** Creates GlobalCache that provides access to global values for user. */
90-
abstract GlobalsCache getGlobalsCache(User user);
89+
/** Creates GlobalCache that provides access to global values. */
90+
abstract GlobalsCache getGlobalsCache();
9191

9292
/** Creates an IndexManager that manages our persisted query indexes. */
9393
abstract IndexManager getIndexManager(User user);

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteGlobalsCache.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ public class SQLiteGlobalsCache implements GlobalsCache{
2222
private static final String DB_TOKEN = "dbToken";
2323
private final SQLitePersistence db;
2424

25-
/** The normalized uid (for example, null => "") used in the uid column. */
26-
private final String uid;
27-
28-
public SQLiteGlobalsCache(SQLitePersistence persistence, User user) {
25+
public SQLiteGlobalsCache(SQLitePersistence persistence) {
2926
this.db = persistence;
30-
this.uid = user.isAuthenticated() ? user.getUid() : "";
3127
}
3228

3329
@Override
@@ -42,17 +38,16 @@ public void setDbToken(ByteString value) {
4238
}
4339

4440
private byte[] get(String global) {
45-
return db.query("SELECT value FROM globals WHERE uid = ? AND global = ?")
46-
.binding(uid, global)
41+
return db.query("SELECT value FROM globals WHERE global = ?")
42+
.binding(global)
4743
.firstValue(row -> row.getBlob(0));
4844
}
4945

5046
private void set(String global, byte[] value) {
5147
db.execute(
5248
"INSERT OR REPLACE INTO globals "
53-
+ "(uid, global, value) "
54-
+ "VALUES (?, ?, ?)",
55-
uid,
49+
+ "(global, value) "
50+
+ "VALUES (?, ?)",
5651
global,
5752
value);
5853
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLitePersistence.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ RemoteDocumentCache getRemoteDocumentCache() {
206206
}
207207

208208
@Override
209-
GlobalsCache getGlobalsCache(User user) {
210-
return new SQLiteGlobalsCache(this, user);
209+
GlobalsCache getGlobalsCache() {
210+
return new SQLiteGlobalsCache(this);
211211
}
212212

213213
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteSchema.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -719,16 +719,14 @@ private void addPendingDataMigration(String migration) {
719719

720720
private void createGlobalsTable() {
721721
ifTablesDontExist(
722-
new String[] {"globals"},
723-
() -> {
724-
// A table of key value pairs by user.
725-
db.execSQL(
726-
"CREATE TABLE globals ("
727-
+ "uid TEXT, "
728-
+ "global TEXT, "
729-
+ "value BLOB, "
730-
+ "PRIMARY KEY (uid, global))");
731-
});
722+
new String[] {"globals"},
723+
() -> {
724+
// A table of key value pairs by user.
725+
db.execSQL(
726+
"CREATE TABLE globals ("
727+
+ "global TEXT PRIMARY KEY, "
728+
+ "value BLOB)");
729+
});
732730
}
733731

734732
private boolean tableExists(String table) {

firebase-firestore/src/test/java/com/google/firebase/firestore/local/GlobalsCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class GlobalsCacheTest {
3333
@Before
3434
public void setUp() {
3535
persistence = getPersistence();
36-
globalsCache = persistence.getGlobalsCache(User.UNAUTHENTICATED);
36+
globalsCache = persistence.getGlobalsCache();
3737
}
3838

3939
@After

0 commit comments

Comments
 (0)