Skip to content

Commit b7e7310

Browse files
committed
Revert DB changes
1 parent 32a526a commit b7e7310

File tree

13 files changed

+67
-55
lines changed

13 files changed

+67
-55
lines changed

packages/database/src/core/CompoundWrite.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Node, NamedNode } from './snap/Node';
2121
import { PRIORITY_INDEX } from './snap/indexes/PriorityIndex';
2222
import { assert } from '@firebase/util';
2323
import { ChildrenNode } from './snap/ChildrenNode';
24+
import { each } from './util/util';
2425

2526
/**
2627
* This class holds a collection of writes that can be applied to nodes in unison. It abstracts away the logic with
@@ -69,9 +70,9 @@ export class CompoundWrite {
6970
*/
7071
addWrites(path: Path, updates: { [name: string]: Node }): CompoundWrite {
7172
let newWrite = this as CompoundWrite;
72-
for (const [childKey, node] of Object.entries(updates)) {
73+
each(updates, function(childKey: string, node: Node) {
7374
newWrite = newWrite.addWrite(path.child(childKey), node);
74-
}
75+
});
7576
return newWrite;
7677
}
7778

packages/database/src/core/Repo.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,14 @@ export class Repo {
403403
let empty = true;
404404
const serverValues = this.generateServerValues();
405405
const changedChildren: { [k: string]: Node } = {};
406-
for (const [changedKey, changedValue] of Object.entries(childrenToMerge)) {
406+
each(childrenToMerge, (changedKey: string, changedValue: any) => {
407407
empty = false;
408408
const newNodeUnresolved = nodeFromJSON(changedValue);
409409
changedChildren[changedKey] = resolveDeferredValueSnapshot(
410410
newNodeUnresolved,
411411
serverValues
412412
);
413-
}
413+
});
414414

415415
if (!empty) {
416416
const writeId = this.getNextWriteId_();
@@ -440,10 +440,10 @@ export class Repo {
440440
}
441441
);
442442

443-
for (const changedPath of Object.keys(childrenToMerge)) {
443+
each(childrenToMerge, (changedPath: string) => {
444444
const affectedPath = this.abortTransactions_(path.child(changedPath));
445445
this.rerunTransactions_(affectedPath);
446-
}
446+
});
447447

448448
// We queued the events above, so just flush the queue here
449449
this.eventQueue_.raiseEventsForChangedPath(path, []);
@@ -566,12 +566,10 @@ export class Repo {
566566
childrenToMerge,
567567
(status, errorReason) => {
568568
if (status === 'ok') {
569-
for (const [childName, childNode] of Object.entries(
570-
childrenToMerge
571-
)) {
569+
each(childrenToMerge, (childName: string, childNode: any) => {
572570
const newChildNode = nodeFromJSON(childNode);
573571
this.onDisconnect_.remember(path.child(childName), newChildNode);
574-
}
572+
});
575573
}
576574
this.callOnCompleteCallback(onComplete, status, errorReason);
577575
}
@@ -653,14 +651,14 @@ export class Repo {
653651
0
654652
);
655653

656-
for (const [stat, value] of Object.entries(stats)) {
654+
each(stats, (stat: string, value: any) => {
657655
let paddedStat = stat;
658656
// pad stat names to be the same length (plus 2 extra spaces).
659657
for (let i = stat.length; i < longestName + 2; i++) {
660658
paddedStat += ' ';
661659
}
662660
console.log(paddedStat + value);
663-
}
661+
});
664662
}
665663

666664
statsIncrementCounter(metric: string) {

packages/database/src/core/RepoInfo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { assert } from '@firebase/util';
1919
import { PersistentStorage } from './storage/storage';
2020
import { LONG_POLLING, WEBSOCKET } from '../realtime/Constants';
21+
import { each } from './util/util';
2122

2223
/**
2324
* A class that holds metadata about a Repo object
@@ -101,9 +102,9 @@ export class RepoInfo {
101102

102103
const pairs: string[] = [];
103104

104-
for (const [key, value] of Object.entries(params)) {
105+
each(params, (key: string, value: string) => {
105106
pairs.push(key + '=' + value);
106-
}
107+
});
107108

108109
return connURL + pairs.join('&');
109110
}

packages/database/src/core/SyncPoint.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,18 @@ export class SyncPoint {
223223
}
224224

225225
getQueryViews(): View[] {
226-
return Array.from(this.views.values()).filter(
227-
view =>
226+
const result = [];
227+
for (const view of this.views.values()) {
228+
if (
228229
!view
229230
.getQuery()
230231
.getQueryParams()
231232
.loadsAllData()
232-
);
233+
) {
234+
result.push(view);
235+
}
236+
}
237+
return result;
233238
}
234239

235240
/**

packages/database/src/core/SyncTree.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { assert } from '@firebase/util';
19-
import { errorForServerCode } from './util/util';
19+
import { errorForServerCode, each } from './util/util';
2020
import { AckUserWrite } from './operation/AckUserWrite';
2121
import { ChildrenNode } from './snap/ChildrenNode';
2222
import { ImmutableTree } from './util/ImmutableTree';
@@ -158,9 +158,9 @@ export class SyncTree {
158158
// overwrite
159159
affectedTree = affectedTree.set(Path.Empty, true);
160160
} else {
161-
for (const [pathString, node] of Object.entries(write.children)) {
161+
each(write.children, function(pathString: string, node: Node) {
162162
affectedTree = affectedTree.set(new Path(pathString), node);
163-
}
163+
});
164164
}
165165
return this.applyOperationToSyncPoints_(
166166
new AckUserWrite(write.path, affectedTree, revert)
@@ -524,9 +524,9 @@ export class SyncTree {
524524
if (maybeChildSyncPoint) {
525525
views = maybeChildSyncPoint.getQueryViews();
526526
}
527-
for (const childViews of Object.values(childMap)) {
527+
each(childMap, function(_key: string, childViews: View[]) {
528528
views = views.concat(childViews);
529-
}
529+
});
530530
return views;
531531
}
532532
}
@@ -611,9 +611,9 @@ export class SyncTree {
611611
maybeChildSyncPoint.getQueryViews().map(view => view.getQuery())
612612
);
613613
}
614-
for (const childQueries of Object.values(childMap)) {
614+
each(childMap, function(_key: string, childQueries: Query[]) {
615615
queries = queries.concat(childQueries);
616-
}
616+
});
617617
return queries;
618618
}
619619
});

packages/database/src/core/WriteTree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ChildrenNode } from './snap/ChildrenNode';
2424
import { NamedNode, Node } from './snap/Node';
2525
import { CacheNode } from './view/CacheNode';
2626
import { Index } from './snap/indexes/Index';
27+
import { each } from './util/util';
2728

2829
/**
2930
* Defines a single user-initiated write operation. May be the result of a set(), transaction(), or update() call. In
@@ -203,11 +204,11 @@ export class WriteTree {
203204
);
204205
} else {
205206
const children = writeToRemove.children;
206-
for (const childName of Object.keys(children)) {
207+
each(children, (childName: string) => {
207208
this.visibleWrites_ = this.visibleWrites_.removeWrite(
208209
writeToRemove.path.child(childName)
209210
);
210-
}
211+
});
211212
}
212213
return true;
213214
}

packages/database/src/core/snap/nodeFromJSON.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { NAME_COMPARATOR, NAME_ONLY_COMPARATOR } from './comparators';
2525
import { IndexMap } from './IndexMap';
2626
import { PRIORITY_INDEX, setNodeFromJSON } from './indexes/PriorityIndex';
2727
import { SortedMap } from '../util/SortedMap';
28+
import { each } from '../util/util';
2829

2930
const USE_HINZE = true;
3031

@@ -68,9 +69,9 @@ export function nodeFromJSON(
6869
if (!(json instanceof Array) && USE_HINZE) {
6970
const children: NamedNode[] = [];
7071
let childrenHavePriority = false;
71-
const hinzeJsonObj: { [k: string]: any } = json as object;
72-
for (const [key, child] of Object.entries(hinzeJsonObj)) {
73-
if (key.substring(0, 1) !== '.') {
72+
const hinzeJsonObj: { [k: string]: any } = json;
73+
each(hinzeJsonObj, (key: string, child: any) => {
74+
if (typeof key !== 'string' || key.substring(0, 1) !== '.') {
7475
// Ignore metadata nodes
7576
const childNode = nodeFromJSON(child);
7677
if (!childNode.isEmpty()) {
@@ -79,7 +80,7 @@ export function nodeFromJSON(
7980
children.push(new NamedNode(key, childNode));
8081
}
8182
}
82-
}
83+
});
8384

8485
if (children.length == 0) {
8586
return ChildrenNode.EMPTY_NODE;
@@ -113,7 +114,7 @@ export function nodeFromJSON(
113114
}
114115
} else {
115116
let node: Node = ChildrenNode.EMPTY_NODE;
116-
for (const [key, childData] of Object.entries(json)) {
117+
each(json, (key: string, childData: any) => {
117118
if (contains(json, key)) {
118119
if (key.substring(0, 1) !== '.') {
119120
// ignore metadata nodes.
@@ -122,7 +123,7 @@ export function nodeFromJSON(
122123
node = node.updateImmediateChild(key, childNode);
123124
}
124125
}
125-
}
126+
});
126127

127128
return node.updatePriority(nodeFromJSON(priority));
128129
}

packages/database/src/core/stats/StatsListener.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { StatsCollection } from './StatsCollection';
19+
import { each } from '../util/util';
1920

2021
/**
2122
* Returns the delta from the previous call to get stats.
@@ -33,9 +34,9 @@ export class StatsListener {
3334

3435
const delta = { ...newStats };
3536
if (this.last_) {
36-
for (const [stat, value] of Object.entries(this.last_)) {
37+
each(this.last_, (stat: string, value: number) => {
3738
delta[stat] = delta[stat] - value;
38-
}
39+
});
3940
}
4041
this.last_ = newStats;
4142

packages/database/src/core/stats/StatsReporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { contains } from '@firebase/util';
19-
import { setTimeoutNonBlocking } from '../util/util';
19+
import { setTimeoutNonBlocking, each } from '../util/util';
2020
import { StatsListener } from './StatsListener';
2121
import { StatsCollection } from './StatsCollection';
2222
import { ServerActions } from '../ServerActions';
@@ -59,12 +59,12 @@ export class StatsReporter {
5959
const reportedStats: typeof stats = {};
6060
let haveStatsToReport = false;
6161

62-
for (const [stat, value] of Object.entries(stats)) {
62+
each(stats, (stat: string, value: number) => {
6363
if (value > 0 && contains(this.statsToReport_, stat)) {
6464
reportedStats[stat] = value;
6565
haveStatsToReport = true;
6666
}
67-
}
67+
});
6868

6969
if (haveStatsToReport) {
7070
this.server_.reportStats(reportedStats);

packages/database/src/core/util/ImmutableTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { SortedMap } from './SortedMap';
1919
import { Path } from './Path';
20-
import { stringCompare } from './util';
20+
import { stringCompare, each } from './util';
2121

2222
let emptyChildrenSingleton: SortedMap<string, ImmutableTree<null>>;
2323

@@ -49,9 +49,9 @@ export class ImmutableTree<T> {
4949
*/
5050
static fromObject<T>(obj: { [k: string]: T }): ImmutableTree<T> {
5151
let tree: ImmutableTree<T> = ImmutableTree.Empty;
52-
for (const [childPath, childSnap] of Object.entries(obj)) {
52+
each(obj, (childPath: string, childSnap: T) => {
5353
tree = tree.set(new Path(childPath), childSnap);
54-
}
54+
});
5555
return tree;
5656
}
5757

packages/database/src/core/util/Tree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { assert } from '@firebase/util';
1919
import { Path } from './Path';
2020
import { contains, safeGet } from '@firebase/util';
21+
import { each } from './util';
2122

2223
/**
2324
* Node in a Tree.
@@ -118,9 +119,9 @@ export class Tree<T> {
118119
* @param {function(!Tree.<T>)} action Action to be called for each child.
119120
*/
120121
forEachChild(action: (tree: Tree<T>) => void) {
121-
for (const [child, childTree] of Object.entries(this.node_.children)) {
122+
each(this.node_.children, (child: string, childTree: TreeNode<T>) => {
122123
action(new Tree<T>(child, this, childTree));
123-
}
124+
});
124125
}
125126

126127
/**

packages/database/src/core/util/validation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { Path, ValidationPath } from './Path';
1919
import { contains, safeGet } from '@firebase/util';
20-
import { isInvalidJSONNumber } from './util';
20+
import { isInvalidJSONNumber, each } from './util';
2121
import { errorPrefix as errorPrefixFxn } from '@firebase/util';
2222
import { stringLength } from '@firebase/util';
2323
import { RepoInfo } from '../RepoInfo';
@@ -171,9 +171,9 @@ export const validateFirebaseData = function(
171171
// TODO = Perf = Consider combining the recursive validation of keys into NodeFromJSON
172172
// to save extra walking of large objects.
173173
if (data && typeof data === 'object') {
174-
let hasDotValue = false,
175-
hasActualChild = false;
176-
for (const [key, value] of Object.entries(data)) {
174+
let hasDotValue = false;
175+
let hasActualChild = false;
176+
each(data, function(key: string, value: any) {
177177
if (key === '.value') {
178178
hasDotValue = true;
179179
} else if (key !== '.priority' && key !== '.sv') {
@@ -194,7 +194,7 @@ export const validateFirebaseData = function(
194194
path.push(key);
195195
validateFirebaseData(errorPrefix, value, path);
196196
path.pop();
197-
}
197+
});
198198

199199
if (hasDotValue && hasActualChild) {
200200
throw new Error(
@@ -286,7 +286,7 @@ export const validateFirebaseMergeDataArg = function(
286286
}
287287

288288
const mergePaths: Path[] = [];
289-
for (const [key, value] of Object.entries(data)) {
289+
each(data, function(key: string, value: any) {
290290
const curPath = new Path(key);
291291
validateFirebaseData(errorPrefix, value, path.child(curPath));
292292
if (curPath.getBack() === '.priority') {
@@ -301,7 +301,7 @@ export const validateFirebaseMergeDataArg = function(
301301
}
302302
}
303303
mergePaths.push(curPath);
304-
}
304+
});
305305
validateFirebaseMergePaths(errorPrefix, mergePaths);
306306
};
307307

0 commit comments

Comments
 (0)