Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
removeQueries -> removeTargets (#23)
Browse files Browse the repository at this point in the history
Requested rename from firebase/firebase-js-sdk#1224, targets is a better
name than queries for internal portions of the SDK.
  • Loading branch information
long1eu committed Oct 15, 2018
1 parent 09370d8 commit 459389a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class LruDelegate {
/// [upperBound], and are not present in the [activeTargetIds] set.
///
/// Returns the number of targets removed.
Future<int> removeQueries(int upperBound, Set<int> activeTargetIds);
Future<int> removeTargets(int upperBound, Set<int> activeTargetIds);

/// Removes all unreferenced documents from the cache that have a sequence
/// number less than or equal to the given sequence number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class LruGarbageCollector {

/// Removes targets with a sequence number equal to or less than the given
/// upper bound, and removes document associations with those targets.
Future<int> removeQueries(int upperBound, Set<int> liveQueries) {
return delegate.removeQueries(upperBound, liveQueries);
Future<int> removeTargets(int upperBound, Set<int> activeTargetIds) {
return delegate.removeTargets(upperBound, activeTargetIds);
}

/// Removes documents that have a sequence number equal to or less than the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MemoryLruReferenceDelegate implements ReferenceDelegate, LruDelegate {
}

@override
Future<int> removeQueries(int upperBound, Set<int> activeTargetIds) async {
Future<int> removeTargets(int upperBound, Set<int> activeTargetIds) async {
return persistence.queryCache.removeQueries(upperBound, activeTargetIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SQLiteLruReferenceDelegate implements ReferenceDelegate, LruDelegate {
}

@override
Future<int> removeQueries(int upperBound, Set<int> activeTargetIds) {
Future<int> removeTargets(int upperBound, Set<int> activeTargetIds) {
return persistence.queryCache.removeQueries(upperBound, activeTargetIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class LruGarbageCollectorTestCase {
await queryCache.removeMatchingKeys(keySet(<DocumentKey>[key]), targetId);
}

Future<int> removeQueries(int upperBound, Set<int> liveQueries) {
Future<int> removeTargets(int upperBound, Set<int> activeTargetIds) {
return persistence.runTransactionAndReturn('Remove queries',
() => garbageCollector.removeQueries(upperBound, liveQueries));
() => garbageCollector.removeTargets(upperBound, activeTargetIds));
}

SetMutation mutation(DocumentKey key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,21 @@ void main() {
});

test('testRemoveQueriesUpThroughSequenceNumber', () async {
final Map<int, QueryData> liveQueries = <int, QueryData>{};
final Map<int, QueryData> activeTargetIds = <int, QueryData>{};
for (int i = 0; i < 100; i++) {
final QueryData queryData = await testCase.addNextQuery();
// Mark odd queries as live so we can test filtering out live queries.
final int targetId = queryData.targetId;
if (targetId % 2 == 1) {
liveQueries[targetId] = queryData;
activeTargetIds[targetId] = queryData;
}
}

// GC up through 20th query, which is 20%.
// Expect to have GC'd 10 targets, since every other target is live
final int upperBound = 20 + testCase.initialSequenceNumber;
final int removed =
await testCase.removeQueries(upperBound, liveQueries.keys.toSet());
await testCase.removeTargets(upperBound, activeTargetIds.keys.toSet());
expect(removed, 10);

// Make sure we removed the even targets with targetID <= 20.
Expand Down Expand Up @@ -425,12 +425,12 @@ void main() {

// Finally, do the garbage collection, up to but not including the removal
// of middleTarget
final Set<int> liveQueries = Set<int>();
liveQueries.add(oldestTarget.targetId);
final int queriesRemoved =
await testCase.garbageCollector.removeQueries(upperBound, liveQueries);
final Set<int> activeTargetIds = Set<int>();
activeTargetIds.add(oldestTarget.targetId);
final int targetsRemoved = await testCase.garbageCollector
.removeTargets(upperBound, activeTargetIds);
// Expect to remove newest target
expect(queriesRemoved, 1);
expect(targetsRemoved, 1);
final int docsRemoved =
await testCase.garbageCollector.removeOrphanedDocuments(upperBound);
expect(docsRemoved, expectedRemoved.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,21 @@ void main() {
});

test('testRemoveQueriesUpThroughSequenceNumber', () async {
final Map<int, QueryData> liveQueries = <int, QueryData>{};
final Map<int, QueryData> activeTargetIds = <int, QueryData>{};
for (int i = 0; i < 100; i++) {
final QueryData queryData = await testCase.addNextQuery();
// Mark odd queries as live so we can test filtering out live queries.
final int targetId = queryData.targetId;
if (targetId % 2 == 1) {
liveQueries[targetId] = queryData;
activeTargetIds[targetId] = queryData;
}
}

// GC up through 20th query, which is 20%.
// Expect to have GC'd 10 targets, since every other target is live
final int upperBound = 20 + testCase.initialSequenceNumber;
final int removed =
await testCase.removeQueries(upperBound, liveQueries.keys.toSet());
await testCase.removeTargets(upperBound, activeTargetIds.keys.toSet());
expect(removed, 10);

// Make sure we removed the even targets with targetID <= 20.
Expand Down Expand Up @@ -429,7 +429,7 @@ void main() {
final Set<int> liveQueries = Set<int>();
liveQueries.add(oldestTarget.targetId);
final int queriesRemoved =
await testCase.garbageCollector.removeQueries(upperBound, liveQueries);
await testCase.garbageCollector.removeTargets(upperBound, liveQueries);
// Expect to remove newest target
expect(queriesRemoved, 1);
final int docsRemoved =
Expand Down

0 comments on commit 459389a

Please sign in to comment.