-
Notifications
You must be signed in to change notification settings - Fork 948
Remove TargetIdGenerator #2818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove TargetIdGenerator #2818
Changes from 1 commit
09aaec4
d251a62
9323c9a
2a9e55e
5797b97
69fe8a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
|
||
import { FieldFilter, Filter, Query } from '../../../src/core/query'; | ||
import { Target } from '../../../src/core/target'; | ||
import { TargetIdGenerator } from '../../../src/core/target_id_generator'; | ||
import { TargetId } from '../../../src/core/types'; | ||
import { | ||
Document, | ||
|
@@ -82,8 +81,7 @@ export class ClientMemoryState { | |
activeTargets: ActiveTargetMap = {}; | ||
queryMapping = new ObjectMap<Target, TargetId>(t => t.canonicalId()); | ||
limboMapping: LimboMap = {}; | ||
|
||
limboIdGenerator: TargetIdGenerator = TargetIdGenerator.forSyncEngine(); | ||
nextLimboTarget = 1; | ||
|
||
constructor() { | ||
this.reset(); | ||
|
@@ -94,7 +92,13 @@ export class ClientMemoryState { | |
this.queryMapping = new ObjectMap<Target, TargetId>(t => t.canonicalId()); | ||
this.limboMapping = {}; | ||
this.activeTargets = {}; | ||
this.limboIdGenerator = TargetIdGenerator.forSyncEngine(); | ||
this.nextLimboTarget = 1; | ||
} | ||
|
||
nextLimboTargetId(): TargetId { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Naming the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
const nextLimboTargetId = this.nextLimboTarget; | ||
this.nextLimboTarget += 2; | ||
return nextLimboTargetId; | ||
} | ||
|
||
/** | ||
|
@@ -112,7 +116,7 @@ export class ClientMemoryState { | |
class CachedTargetIdGenerator { | ||
// TODO(wuandy): rename this to targetMapping. | ||
private queryMapping = new ObjectMap<Target, TargetId>(t => t.canonicalId()); | ||
private targetIdGenerator = TargetIdGenerator.forTargetCache(); | ||
private nextTargetId = 2; | ||
|
||
/** | ||
* Returns a cached target ID for the provided Target, or a new ID if no | ||
|
@@ -122,7 +126,8 @@ class CachedTargetIdGenerator { | |
if (this.queryMapping.has(target)) { | ||
return this.queryMapping.get(target)!; | ||
} | ||
const targetId = this.targetIdGenerator.next(); | ||
const targetId = this.nextTargetId; | ||
this.nextTargetId += 2; | ||
this.queryMapping.set(target, targetId); | ||
return targetId; | ||
} | ||
|
@@ -170,8 +175,8 @@ export class SpecBuilder { | |
return this.currentClientState; | ||
} | ||
|
||
private get limboIdGenerator(): TargetIdGenerator { | ||
return this.clientState.limboIdGenerator; | ||
private nextLimboTargetId(): TargetId { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here; consider renaming the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return this.clientState.nextLimboTargetId(); | ||
} | ||
|
||
private get queryMapping(): ObjectMap<Target, TargetId> { | ||
|
@@ -450,7 +455,7 @@ export class SpecBuilder { | |
const path = key.path.canonicalString(); | ||
// Create limbo target ID mapping if it was not in limbo yet | ||
if (!objUtils.contains(this.limboMapping, path)) { | ||
this.limboMapping[path] = this.limboIdGenerator.next(); | ||
this.limboMapping[path] = this.nextLimboTargetId(); | ||
} | ||
// Limbo doc queries are always without resume token | ||
this.addQueryToActiveTargets( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that was nice about the separate class was that it fully encapsulated this post-increment semantic (that is: get the current value and then bump). Now different locations are using this differently and it's not obvious how this is supposed to work.
In particular, it's a little weird that
MemoryTargetCache
doesn't use the appropriateTARGET_ID
initializer and doesn't do the post-increment dance, though I guess that's sort of intended?It's also telling that the client state implements this as a method.
In several cases in this review I had to work to convince myself that this was going to generate the correct initial value and this is uncomfortable.
I bet you'd get most of the size benefit (possibly a bit more), just by simplifying the internals, having a constructor that just takes the initial values you've exported, and possibly removing
seek
/after
and having those callers just new up a newTargetIdGenerator
with their desired seed.