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

Remove extra calls to bind when not attached #21213

Merged
merged 9 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 1 addition & 23 deletions experimental/dds/attributable-map/src/mapKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import { IFluidHandle } from "@fluidframework/core-interfaces";
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions";
import { AttributionKey } from "@fluidframework/runtime-definitions/internal";
import {
IFluidSerializer,
ValueType,
bindHandles,
} from "@fluidframework/shared-object-base/internal";
import { IFluidSerializer, ValueType } from "@fluidframework/shared-object-base/internal";

// eslint-disable-next-line import/no-deprecated
import { ISerializableValue, ISerializedValue, ISharedMapEvents } from "./interfaces.js";
Expand Down Expand Up @@ -84,8 +80,6 @@ export interface IMapDataObjectSerialized {
type MapKeyLocalOpMetadata = IMapKeyEditLocalOpMetadata | IMapKeyAddLocalOpMetadata;
type MapLocalOpMetadata = IMapClearLocalOpMetadata | MapKeyLocalOpMetadata;

/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know why these aren't necessary anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they were unrelated, but I have format on save turned on and it removed a bunch of lints that were no longer used apparently.


function isMapKeyLocalOpMetadata(metadata: any): metadata is MapKeyLocalOpMetadata {
return (
metadata !== undefined &&
Expand All @@ -110,8 +104,6 @@ function isMapLocalOpMetadata(metadata: any): metadata is MapLocalOpMetadata {
);
}

/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access */

function createClearLocalOpMetadata(
op: IMapClearOperation,
pendingClearMessageId: number,
Expand Down Expand Up @@ -216,7 +208,6 @@ export class AttributableMapKernel {
* @returns The iterator
*/
// TODO: Use `unknown` instead (breaking change).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public entries(): IterableIterator<[string, any]> {
const localEntriesIterator = this.data.entries();
const iterator = {
Expand All @@ -239,7 +230,6 @@ export class AttributableMapKernel {
* @returns The iterator
*/
// TODO: Use `unknown` instead (breaking change).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public values(): IterableIterator<any> {
const localValuesIterator = this.data.values();
const iterator = {
Expand All @@ -262,7 +252,6 @@ export class AttributableMapKernel {
* @returns The iterator
*/
// TODO: Use `unknown` instead (breaking change).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public [Symbol.iterator](): IterableIterator<[string, any]> {
return this.entries();
}
Expand All @@ -274,7 +263,6 @@ export class AttributableMapKernel {
public forEach(
callbackFn: (value: unknown, key: string, map: Map<string, unknown>) => void,
): void {
// eslint-disable-next-line unicorn/no-array-for-each
this.data.forEach((localValue, key, m) => {
callbackFn(localValue.value, key, m);
});
Expand All @@ -284,7 +272,6 @@ export class AttributableMapKernel {
* {@inheritDoc ISharedMap.get}
*/
// TODO: Use `unknown` instead (breaking change).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public get<T = any>(key: string): T | undefined {
const localValue = this.data.get(key);
return localValue === undefined ? undefined : (localValue.value as T);
Expand Down Expand Up @@ -317,10 +304,6 @@ export class AttributableMapKernel {

// If we are not attached, don't submit the op.
if (!this.isAttached()) {
// this is necessary to bind the potential handles in the value
// to this DDS, as we do not walk the object normally unless we
// are attached
bindHandles(localValue.value, this.serializer, this.handle);
return;
}

Expand Down Expand Up @@ -546,14 +529,11 @@ export class AttributableMapKernel {
return true;
}

/* eslint-disable @typescript-eslint/no-unsafe-member-access */

/**
* Rollback a local op
* @param op - The operation to rollback
* @param localOpMetadata - The local metadata associated with the op.
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
public rollback(op: any, localOpMetadata: unknown): void {
if (!isMapLocalOpMetadata(localOpMetadata)) {
throw new Error("Invalid localOpMetadata");
Expand Down Expand Up @@ -599,8 +579,6 @@ export class AttributableMapKernel {
}
}

/* eslint-enable @typescript-eslint/no-unsafe-member-access */

/**
* Set implementation used for both locally sourced sets as well as incoming remote sets.
* @param key - The key being set
Expand Down
17 changes: 9 additions & 8 deletions packages/dds/map/src/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import type {
} from "@fluidframework/runtime-definitions/internal";
import { SummaryTreeBuilder } from "@fluidframework/runtime-utils/internal";
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
import { SharedObject, ValueType, parseHandles } from "@fluidframework/shared-object-base/internal";
import {
SharedObject,
ValueType,
bindHandles,
parseHandles,
} from "@fluidframework/shared-object-base/internal";
import { type ITelemetryLoggerExt, UsageError } from "@fluidframework/telemetry-utils/internal";
import path from "path-browserify";

Expand All @@ -38,7 +43,7 @@ import type {
ISerializedValue,
} from "./internalInterfaces.js";
import type { ILocalValue } from "./localValues.js";
import { LocalValueMaker, makeSerializable } from "./localValues.js";
import { LocalValueMaker } from "./localValues.js";

// We use path-browserify since this code can run safely on the server or the browser.
// We standardize on using posix slashes everywhere.
Expand Down Expand Up @@ -1307,11 +1312,7 @@ class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirec

// Create a local value and serialize it.
jzaffiro marked this conversation as resolved.
Show resolved Hide resolved
const localValue = this.directory.localValueMaker.fromInMemory(value);
const serializableValue = makeSerializable(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markfields I actually don't think this can be removed - without this, the visibility of the datastores is not getting set correctly. This also predated #19242, so I would think it's ok to leave.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed - sounds like a bug. We'll follow up separately.

localValue,
this.serializer,
this.directory.handle,
);
bindHandles(localValue, this.serializer, this.directory.handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For when we revisit this - I think it can/should go in the isAttached block


// Set the value locally.
const previousValue = this.setCore(key, localValue, true);
Expand All @@ -1325,7 +1326,7 @@ class SubDirectory extends TypedEventEmitter<IDirectoryEvents> implements IDirec
key,
path: this.absolutePath,
type: "set",
value: serializableValue,
value: { type: localValue.type, value: localValue.value as unknown },
};
this.submitKeyMessage(op, previousValue);
return this;
Expand Down
6 changes: 1 addition & 5 deletions packages/dds/map/src/mapKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { TypedEventEmitter } from "@fluid-internal/client-utils";
import type { IFluidHandle } from "@fluidframework/core-interfaces";
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
import type { IFluidSerializer } from "@fluidframework/shared-object-base/internal";
import { ValueType, bindHandles } from "@fluidframework/shared-object-base/internal";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also delete this function, it's not used anywhere else, and isn't an ideal implementation. @Abe27342 what's the task you pinged me about fixing the function? We can close it if this PR works out.

import { ValueType } from "@fluidframework/shared-object-base/internal";

import type { ISharedMapEvents } from "./interfaces.js";
import type {
Expand Down Expand Up @@ -299,10 +299,6 @@ export class MapKernel {

// If we are not attached, don't submit the op.
if (!this.isAttached()) {
// this is necessary to bind the potential handles in the value
// to this DDS, as we do not walk the object normally unless we
// are attached
bindHandles(localValue.value, this.serializer, this.handle);
return;
}

Expand Down
Loading