Skip to content
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

feat(presence): Add support for signal batching #23075

Draft
wants to merge 61 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f7b7b1f
wip
tylerbutler Oct 23, 2024
c334545
wip
tylerbutler Oct 28, 2024
dbf7f39
wip
tylerbutler Oct 30, 2024
54a6226
Merge branch 'main' into presence-notification-events
tylerbutler Oct 31, 2024
93b12e9
compiles and test passes
tylerbutler Oct 31, 2024
e882b2a
process incoming signal
tylerbutler Oct 31, 2024
b44725a
sort of works
tylerbutler Oct 31, 2024
0f6b6f3
cleanup
tylerbutler Nov 1, 2024
f7e7d30
updates
tylerbutler Nov 1, 2024
a0b348d
Merge branch 'main' into presence-notification-events
tylerbutler Nov 5, 2024
b3dccb0
Merge branch 'main' into presence-notification-events
tylerbutler Nov 11, 2024
321ae56
Apply suggestions from code review
tylerbutler Nov 11, 2024
f396549
Apply suggestions from code review
tylerbutler Nov 11, 2024
f819b42
revert changes in example
tylerbutler Nov 11, 2024
47b8f87
cleanup
tylerbutler Nov 11, 2024
5e9022c
simplify and correct tests
tylerbutler Nov 12, 2024
af8f94d
Merge branch 'main' into presence-notification-events
tylerbutler Nov 12, 2024
01df10c
feedback
tylerbutler Nov 12, 2024
b378f62
build
tylerbutler Nov 12, 2024
850afed
Merge branch 'main' into presence-notification-events
tylerbutler Nov 12, 2024
15d2457
refactor(presence): Convert localUpdate to accept an options object
tylerbutler Nov 12, 2024
b0b0bd4
Merge branch 'main' into presence-batching
tylerbutler Nov 12, 2024
538992e
test(client-presence): rework Notifications tests
jason-ha Nov 13, 2024
eb731f6
test cases for signals in latestValueManager
tylerbutler Nov 13, 2024
24d43da
Merge pull request #30 from microsoft/presence/notification-events-tests
tylerbutler Nov 13, 2024
e78e7ee
initial implemtnation
tylerbutler Nov 13, 2024
7c7d9bd
Merge branch 'main' into presence-notification-events
tylerbutler Nov 13, 2024
f10c6fc
Merge branch 'main' into presence-notification-events
tylerbutler Nov 13, 2024
2575489
fix initial subscriptions not being triggered
tylerbutler Nov 13, 2024
9ff6a36
Merge branch 'presence-notification-events' into presence-batching
tylerbutler Nov 13, 2024
b4ad324
Remove outdated comments
tylerbutler Nov 13, 2024
e27b44f
Remove outdated comments
tylerbutler Nov 13, 2024
9be169e
Merge branch 'main' into presence-notification-events
tylerbutler Nov 13, 2024
39aeb75
wip
tylerbutler Nov 13, 2024
eac6314
restore datastore manager
tylerbutler Nov 13, 2024
57c077c
Revert "restore datastore manager"
tylerbutler Nov 13, 2024
b935bf6
wip
tylerbutler Nov 13, 2024
3204642
vitest
tylerbutler Nov 13, 2024
d445834
snapshot tests
tylerbutler Nov 13, 2024
e92b727
updates
tylerbutler Nov 14, 2024
58eaf28
Merge branch 'main' into presence-batching
tylerbutler Nov 14, 2024
68c91f5
test updates
tylerbutler Nov 14, 2024
138fe43
Update presenceDatastoreManager.ts
tylerbutler Nov 14, 2024
018f3eb
Update presenceDatastoreManager.ts
tylerbutler Nov 14, 2024
d76623e
Update presenceDatastoreManager.ts
tylerbutler Nov 14, 2024
5f58a86
Update presenceDatastoreManager.ts
tylerbutler Nov 14, 2024
7ebe231
Update presenceDatastoreManager.ts
tylerbutler Nov 14, 2024
5a0e88b
clean up typing
tylerbutler Nov 14, 2024
81a3679
Merge branch 'main' into presence-notification-events
tylerbutler Nov 14, 2024
2e06968
Merge branch 'presence-notification-events' into presence-batching
tylerbutler Nov 14, 2024
5627b10
Merge branch 'presence-notification-events' into presence-batching
tylerbutler Nov 14, 2024
d3a010e
update tests
tylerbutler Nov 14, 2024
902671c
disable object sorting in snapshots
tylerbutler Nov 14, 2024
9257e8c
Merge branch 'main' into presence-batching
tylerbutler Nov 14, 2024
944fc73
use ts-deepmerge
tylerbutler Nov 14, 2024
f22a9ae
stringify snapshot since order controls don't seem to work
tylerbutler Nov 14, 2024
77c5407
clarify that snapshot sort config doesn't work
tylerbutler Nov 14, 2024
8bd0558
Merge branch 'main' into presence-batching
tylerbutler Nov 14, 2024
2dde9ea
add code coverage support
tylerbutler Nov 14, 2024
50bcb3e
ignore test setup signals in snapshots
tylerbutler Nov 14, 2024
7114a8d
placeholder test
tylerbutler Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/framework/presence/src/latestMapValueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
LatestValueMetadata,
} from "./latestValueTypes.js";
import type { ClientSessionId, ISessionClient, SpecificSessionClient } from "./presence.js";
import type { LocalUpdateOptions } from "./presenceStates.js";
import { datastoreFromHandle, type StateDatastore } from "./stateDatastore.js";
import { brandIVM } from "./valueManager.js";

Expand Down Expand Up @@ -191,7 +192,7 @@ class ValueMapImpl<T, K extends string | number> implements ValueMap<K, T> {
private readonly value: InternalTypes.MapValueState<T>,
private readonly localUpdate: (
updates: InternalTypes.MapValueState<T>,
forceUpdate: boolean,
options: LocalUpdateOptions,
) => void,
) {
// All initial items are expected to be defined.
Expand All @@ -210,7 +211,7 @@ class ValueMapImpl<T, K extends string | number> implements ValueMap<K, T> {
item.value = value;
}
const update = { rev: this.value.rev, items: { [key]: item } };
this.localUpdate(update, /* forceUpdate */ false);
this.localUpdate(update, { forceBroadcast: false });
}

public clear(): void {
Expand Down Expand Up @@ -333,8 +334,8 @@ class LatestMapValueManagerImpl<

this.local = new ValueMapImpl<T, Keys>(
value,
(updates: InternalTypes.MapValueState<T>, forceUpdate: boolean) => {
datastore.localUpdate(key, updates, forceUpdate);
(updates: InternalTypes.MapValueState<T>, options: LocalUpdateOptions) => {
datastore.localUpdate(key, updates, options);
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/presence/src/latestValueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class LatestValueManagerImpl<T, Key extends string>
this.value.rev += 1;
this.value.timestamp = Date.now();
this.value.value = value;
this.datastore.localUpdate(this.key, this.value, /* forceUpdate */ false);
this.datastore.localUpdate(this.key, this.value, { forceBroadcast: false });
}

public *clientValues(): IterableIterator<LatestValueClientData<T>> {
Expand Down
7 changes: 4 additions & 3 deletions packages/framework/presence/src/presenceDatastoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { IEphemeralRuntime } from "./internalTypes.js";
import type { ClientSessionId, ISessionClient } from "./presence.js";
import type {
ClientUpdateEntry,
LocalUpdateOptions,
PresenceStatesInternal,
ValueElementMap,
} from "./presenceStates.js";
Expand Down Expand Up @@ -148,7 +149,7 @@ export class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {

const localUpdate = (
states: { [key: string]: ClientUpdateEntry },
forceBroadcast: boolean,
options: LocalUpdateOptions,
): void => {
// Check for connectivity before sending updates.
if (!this.runtime.connected) {
Expand Down Expand Up @@ -177,7 +178,7 @@ export class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {
},
[internalWorkspaceAddress]: updates,
},
forceBroadcast,
options,
);
};

Expand All @@ -195,7 +196,7 @@ export class PresenceDatastoreManagerImpl implements PresenceDatastoreManager {
return entry.public;
}

private localUpdate(data: DatastoreMessageContent, _forceBroadcast: boolean): void {
private localUpdate(data: DatastoreMessageContent, options: LocalUpdateOptions): void {
const content = {
sendTimestamp: Date.now(),
avgLatency: this.averageLatency,
Expand Down
18 changes: 13 additions & 5 deletions packages/framework/presence/src/presenceStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ export type MapSchemaElement<
Keys extends keyof TSchema = keyof TSchema,
> = ReturnType<TSchema[Keys]>[Part];

/**
* @internal
*/
export interface LocalUpdateOptions {
forceBroadcast: boolean;
allowableUpdateLatency?: number;
}

/**
* @internal
*/
export interface PresenceRuntime {
readonly clientSessionId: ClientSessionId;
lookupClient(clientId: ClientConnectionId): ISessionClient;
localUpdate(states: { [key: string]: ClientUpdateEntry }, forceBroadcast: boolean): void;
localUpdate(states: { [key: string]: ClientUpdateEntry }, options: LocalUpdateOptions): void;
}

type PresenceSubSchemaFromWorkspaceSchema<
Expand Down Expand Up @@ -242,7 +250,7 @@ class PresenceStatesImpl<TSchema extends PresenceStatesSchema>
this.props = this.nodes as unknown as PresenceStates<TSchema>["props"];

if (anyInitialValues) {
this.runtime.localUpdate(initial.newValues, false);
this.runtime.localUpdate(initial.newValues, { forceBroadcast: false });
}
}
}
Expand All @@ -262,9 +270,9 @@ class PresenceStatesImpl<TSchema extends PresenceStatesSchema>
public localUpdate<Key extends keyof TSchema & string>(
key: Key,
value: MapSchemaElement<TSchema, "value", Key> & ClientUpdateEntry,
forceBroadcast: boolean,
options: LocalUpdateOptions,
): void {
this.runtime.localUpdate({ [key]: value }, forceBroadcast);
this.runtime.localUpdate({ [key]: value }, options);
}

public update<Key extends keyof TSchema & string>(
Expand Down Expand Up @@ -301,7 +309,7 @@ class PresenceStatesImpl<TSchema extends PresenceStatesSchema>
this.datastore[key] = {};
}
this.datastore[key][this.runtime.clientSessionId] = nodeData.value;
this.runtime.localUpdate({ [key]: nodeData.value }, false);
this.runtime.localUpdate({ [key]: nodeData.value }, { forceBroadcast: false });
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/framework/presence/src/stateDatastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ClientConnectionId } from "./baseTypes.js";
import type { InternalTypes } from "./exposedInternalTypes.js";
import type { ClientRecord } from "./internalTypes.js";
import type { ClientSessionId, ISessionClient } from "./presence.js";
import type { LocalUpdateOptions } from "./presenceStates.js";

// type StateDatastoreSchemaNode<
// TValue extends InternalTypes.ValueDirectoryOrState<any> = InternalTypes.ValueDirectoryOrState<unknown>,
Expand Down Expand Up @@ -35,7 +36,7 @@ export interface StateDatastore<
value: TValue & {
ignoreUnmonitored?: true;
},
forceBroadcast: boolean,
options: LocalUpdateOptions,
): void;
update(key: TKey, clientSessionId: ClientSessionId, value: TValue): void;
knownValues(key: TKey): {
Expand Down
Loading