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

fix: Fix a bug that caused some unassigned face photos to be unselectable #774

Merged

Conversation

g3n35i5
Copy link
Contributor

@g3n35i5 g3n35i5 commented Aug 16, 2023

This resolves #721

@g3n35i5
Copy link
Contributor Author

g3n35i5 commented Aug 16, 2023

I really hope that I have not broken anything with this 😆 But it works for me so far, I look forward to feedback!

@@ -228,7 +283,7 @@ export type ISelectionAction = {
/** Icon component */
icon: any;
/** Action to perform */
callback: (selection: Map<number, IPhoto>) => Promise<void>;
callback: (selection: any) => Promise<void>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type should be SelectionProxy but this doesn't work. Can someone help out here?

@g3n35i5 g3n35i5 force-pushed the fix/unassigned-faces-selection-problem branch 2 times, most recently from 17433bb to e3e20f9 Compare August 19, 2023 10:01
Copy link
Owner

@pulsejet pulsejet left a comment

Choose a reason for hiding this comment

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

Thanks for this @g3n35i5. I'll go ahead and merge this in with a few updates today.

BTW #773 is related to aggravating this issue; that patch might help.

Comment on lines +248 to +256
let photosToDelete: IPhoto[] = []
for (const photo of selection.values()) {
if (photo === undefined) {
continue
}
if (delIds.indexOf(photo.fileid) > -1) {
photosToDelete.push(photo)
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

  1. Why not just selection.values().filter( ... )?
  2. Can get a safer time complexity by making delIds a Set first

Comment on lines 581 to +584
// Only do this if the photo in the selection set is this one.
// The problem arises when there are duplicates (e.g. face rect)
// in the list, which creates an inconsistent state if we do this.
if (this.selection.get(photo.fileid) === photo) {
this.selection.delete(photo.fileid);
if (this.selection.get(photo) === photo) {
Copy link
Owner

Choose a reason for hiding this comment

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

This comment and check should no longer be relevant.

@@ -220,6 +220,61 @@ export type ITick = {
key?: number;
};

export class SelectionProxy {
Copy link
Owner

Choose a reason for hiding this comment

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

types.ts is intended only for interfaces, not implementations (this way, you can import type ...). This class can move to another file.

}

get(photo: IPhoto): IPhoto | undefined {
return this.map.get(photo.key!);
Copy link
Owner

Choose a reason for hiding this comment

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

This, precisely, could be the issue. Photo.key is nullable because, well, it can be null. The bang operator discards this information without a check. There are indeed a bunch of places where we "fake" a IPhoto object that doesn't have a key.

By now though, I'm hoping the selection manager doesn't have to deal with these things. So a runtime assertion here might suffice, so we know if something breaks.

@pulsejet pulsejet merged commit 293421f into pulsejet:master Aug 19, 2023
@g3n35i5 g3n35i5 deleted the fix/unassigned-faces-selection-problem branch August 27, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unassigned face > selection problem
2 participants