Skip to content

Commit 407d9b8

Browse files
author
Michael Lehenbauer
committed
Merge branch 'master' into mikelehen/collection-group-queries
2 parents 3034b0a + 859b7fc commit 407d9b8

File tree

7 files changed

+51
-31
lines changed

7 files changed

+51
-31
lines changed

firebase-common/src/main/java/com/google/firebase/platforminfo/DefaultUserAgentPublisher.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
*/
2828
public class DefaultUserAgentPublisher implements UserAgentPublisher {
2929
private final String javaSDKVersionUserAgent;
30-
private final OutOfBandLibraryVersionRegistrar gamesSDKRegistrar;
30+
private final GlobalLibraryVersionRegistrar gamesSDKRegistrar;
3131

3232
DefaultUserAgentPublisher(
33-
Set<LibraryVersion> libraryVersions, OutOfBandLibraryVersionRegistrar gamesSDKRegistrar) {
33+
Set<LibraryVersion> libraryVersions, GlobalLibraryVersionRegistrar gamesSDKRegistrar) {
3434
this.javaSDKVersionUserAgent = toUserAgent(libraryVersions);
3535
this.gamesSDKRegistrar = gamesSDKRegistrar;
3636
}
@@ -70,7 +70,7 @@ public static Component<UserAgentPublisher> component() {
7070
.factory(
7171
c ->
7272
new DefaultUserAgentPublisher(
73-
c.setOf(LibraryVersion.class), OutOfBandLibraryVersionRegistrar.getInstance()))
73+
c.setOf(LibraryVersion.class), GlobalLibraryVersionRegistrar.getInstance()))
7474
.build();
7575
}
7676
}
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
/**
2222
* In order to allow the C++ and Unity SDKs to publish their versions without the use of the
2323
* components framework, we have a mechanism where the versions can be wired as out of band as side
24-
* effects. See {@link OutOfBandLibraryVersionRegistrar#registerVersion(String, String)}
24+
* effects. See {@link GlobalLibraryVersionRegistrar#registerVersion(String, String)}
2525
*
2626
* <p>Java libraries should use {@link LibraryVersionComponent#create(String, String)} instead.
2727
*/
28-
public class OutOfBandLibraryVersionRegistrar {
28+
public class GlobalLibraryVersionRegistrar {
2929
private final Set<LibraryVersion> infos = new HashSet<>();
30-
private static volatile OutOfBandLibraryVersionRegistrar INSTANCE;
30+
private static volatile GlobalLibraryVersionRegistrar INSTANCE;
3131

32-
OutOfBandLibraryVersionRegistrar() {}
32+
GlobalLibraryVersionRegistrar() {}
3333

3434
/**
3535
* Thread safe method to publish versions outside of the components mechanics.
@@ -49,14 +49,14 @@ Set<LibraryVersion> getRegisteredVersions() {
4949
}
5050
}
5151

52-
/** Returns an instance of {@link OutOfBandLibraryVersionRegistrar} */
53-
public static OutOfBandLibraryVersionRegistrar getInstance() {
54-
OutOfBandLibraryVersionRegistrar localRef = INSTANCE;
52+
/** Returns an instance of {@link GlobalLibraryVersionRegistrar} */
53+
public static GlobalLibraryVersionRegistrar getInstance() {
54+
GlobalLibraryVersionRegistrar localRef = INSTANCE;
5555
if (localRef == null) {
56-
synchronized (OutOfBandLibraryVersionRegistrar.class) {
56+
synchronized (GlobalLibraryVersionRegistrar.class) {
5757
localRef = INSTANCE;
5858
if (localRef == null) {
59-
INSTANCE = localRef = new OutOfBandLibraryVersionRegistrar();
59+
INSTANCE = localRef = new GlobalLibraryVersionRegistrar();
6060
}
6161
}
6262
}

firebase-common/src/test/java/com/google/firebase/platforminfo/DefaultUserAgentPublisherTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@
3030
public class DefaultUserAgentPublisherTest {
3131
private Set<LibraryVersion> libraryVersions;
3232
private DefaultUserAgentPublisher userAgentPublisher;
33-
private OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar;
33+
private GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar;
3434

3535
@Before
3636
public void before() {
3737
libraryVersions = new HashSet<>();
3838
libraryVersions.add(LibraryVersion.create("foo", "1"));
3939
libraryVersions.add(LibraryVersion.create("bar", "2"));
4040

41-
outOfBandLibraryVersionRegistrar = mock(OutOfBandLibraryVersionRegistrar.class);
41+
globalLibraryVersionRegistrar = mock(GlobalLibraryVersionRegistrar.class);
4242

43-
when(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(new HashSet<>());
43+
when(globalLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(new HashSet<>());
4444

4545
userAgentPublisher =
46-
new DefaultUserAgentPublisher(libraryVersions, outOfBandLibraryVersionRegistrar);
46+
new DefaultUserAgentPublisher(libraryVersions, globalLibraryVersionRegistrar);
4747
}
4848

4949
@Test
@@ -59,7 +59,7 @@ public void getUserAgent_createsConcatenatedStringOfSdkVersions() {
5959
@Test
6060
public void getUserAgent_returnsEmptyString_whenVersionSetIsEmpty() {
6161
userAgentPublisher =
62-
new DefaultUserAgentPublisher(new HashSet<>(), outOfBandLibraryVersionRegistrar);
62+
new DefaultUserAgentPublisher(new HashSet<>(), globalLibraryVersionRegistrar);
6363

6464
assertThat(userAgentPublisher.getUserAgent()).isEqualTo("");
6565
}
@@ -71,9 +71,9 @@ public void getUserAgent_returnsEmptyString_whenVersionSetIsEmpty() {
7171
HashSet<LibraryVersion> gamesLibraryVersions = new HashSet<>();
7272
gamesLibraryVersions.add(LibraryVersion.create("fizz", "1"));
7373
gamesLibraryVersions.add(LibraryVersion.create("buzz", "2"));
74-
when(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(gamesLibraryVersions);
74+
when(globalLibraryVersionRegistrar.getRegisteredVersions()).thenReturn(gamesLibraryVersions);
7575
userAgentPublisher =
76-
new DefaultUserAgentPublisher(libraryVersions, outOfBandLibraryVersionRegistrar);
76+
new DefaultUserAgentPublisher(libraryVersions, globalLibraryVersionRegistrar);
7777

7878
String[] actualUserAgent = userAgentPublisher.getUserAgent().split(" ");
7979
Arrays.sort(actualUserAgent);
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
import org.junit.runners.JUnit4;
2222

2323
@RunWith(JUnit4.class)
24-
public class OutOfBandLibraryVersionRegistrarTest {
24+
public class GlobalLibraryVersionRegistrarTest {
2525
@Test
2626
public void registerVersion_persistsVersion() {
27-
OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar =
28-
new OutOfBandLibraryVersionRegistrar();
29-
outOfBandLibraryVersionRegistrar.registerVersion("foo", "1.1.1");
27+
GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar =
28+
new GlobalLibraryVersionRegistrar();
29+
globalLibraryVersionRegistrar.registerVersion("foo", "1.1.1");
3030

31-
assertThat(outOfBandLibraryVersionRegistrar.getRegisteredVersions())
31+
assertThat(globalLibraryVersionRegistrar.getRegisteredVersions())
3232
.contains(LibraryVersion.create("foo", "1.1.1"));
3333
}
3434

3535
@Test
3636
public void getRegisteredVersions_returnsEmptySet_whenNoVersionsAreRegistered() {
37-
OutOfBandLibraryVersionRegistrar outOfBandLibraryVersionRegistrar =
38-
new OutOfBandLibraryVersionRegistrar();
37+
GlobalLibraryVersionRegistrar globalLibraryVersionRegistrar =
38+
new GlobalLibraryVersionRegistrar();
3939

40-
assertThat(outOfBandLibraryVersionRegistrar.getRegisteredVersions()).isEmpty();
40+
assertThat(globalLibraryVersionRegistrar.getRegisteredVersions()).isEmpty();
4141
}
4242
}

firebase-firestore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Unreleased
22
- [feature] You can now query across all collections in your database with a
33
given collection ID using the `FirebaseFirestore.collectionGroup()` method.
4+
- [fixed] Fixed calculation of SQLite database size on Android 9 Pie devices.
5+
Previous method could be off by a few MBs on these devices, potentially
6+
delaying garbage collection.
47

58
# 18.0.1
69
- [fixed] Fixed an issue where Firestore would crash if handling write batches

firebase-firestore/firebase-firestore.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ android {
8383
sourceCompatibility JavaVersion.VERSION_1_8
8484
targetCompatibility JavaVersion.VERSION_1_8
8585
}
86+
testOptions.unitTests.includeAndroidResources = true
8687
}
8788

8889
dependencies {

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.google.firebase.firestore.util.Consumer;
3535
import com.google.firebase.firestore.util.Logger;
3636
import com.google.firebase.firestore.util.Supplier;
37-
import java.io.File;
3837
import java.io.UnsupportedEncodingException;
3938
import java.net.URLEncoder;
4039
import java.util.ArrayList;
@@ -77,7 +76,6 @@ public static String databaseName(String persistenceKey, DatabaseId databaseId)
7776
private final OpenHelper opener;
7877
private final LocalSerializer serializer;
7978
private SQLiteDatabase db;
80-
private File databasePath;
8179
private boolean started;
8280
private final SQLiteQueryCache queryCache;
8381
private final SQLiteIndexManager indexManager;
@@ -107,7 +105,6 @@ public SQLitePersistence(
107105
LruGarbageCollector.Params params) {
108106
String databaseName = databaseName(persistenceKey, databaseId);
109107
this.opener = new OpenHelper(context, databaseName);
110-
this.databasePath = context.getDatabasePath(databaseName);
111108
this.serializer = serializer;
112109
this.queryCache = new SQLiteQueryCache(this, this.serializer);
113110
this.indexManager = new SQLiteIndexManager(this);
@@ -206,7 +203,26 @@ <T> T runTransaction(String action, Supplier<T> operation) {
206203
}
207204

208205
long getByteSize() {
209-
return databasePath.length();
206+
return getPageCount() * getPageSize();
207+
}
208+
209+
/**
210+
* Gets the page size of the database. Typically 4096.
211+
*
212+
* @see https://www.sqlite.org/pragma.html#pragma_page_size
213+
*/
214+
private long getPageSize() {
215+
return query("PRAGMA page_size").firstValue(row -> row.getLong(/*column=*/ 0));
216+
}
217+
218+
/**
219+
* Gets the number of pages in the database file. Multiplying this with the page size yields the
220+
* approximate size of the database on disk (including the WAL, if relevant).
221+
*
222+
* @see https://www.sqlite.org/pragma.html#pragma_page_count.
223+
*/
224+
private long getPageCount() {
225+
return query("PRAGMA page_count").firstValue(row -> row.getLong(/*column=*/ 0));
210226
}
211227

212228
/**

0 commit comments

Comments
 (0)