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

COMPASS-541 Filter lost when inserting a new document #694

Closed
wants to merge 6 commits into from

Conversation

pzrq
Copy link
Contributor

@pzrq pzrq commented Dec 16, 2016

No description provided.

@pzrq pzrq changed the title COMPASS-541 Handle document insert with a filter applied COMPASS-541 Filter lost when inserting a new document Dec 16, 2016
@pzrq
Copy link
Contributor Author

pzrq commented Dec 16, 2016

Looks like something is toggling the indexes sort order when an index is created, completely unrelated to this change as it also broke master earlier. EDIT: COMPASS-564: #695

@satyasinha
Copy link

LGTM, though it seems like the functional tests don't pass (but this issue is also in master) and needs a rebase.

@satyasinha
Copy link

jsdoc warnings

There are these warnings though that were introduced (not from this PR)

Start by adding functional tests to cover the filtered flows.
As there may be other clients interacting with the same mongod, so we can't just increment the count "this.state.count" as was done previously.
Implemented by having the ResetDocumentListStore keep track of the lastKnownFilter.
Note: Robomongo also does this.
So you are likely to see the document you just inserted.
At least until mongodb decides to handle:
https://en.wikipedia.org/wiki/Year_2038_problem
@pzrq pzrq force-pushed the COMPASS-541-insert-plus-filter branch from e28c2c6 to 5298dda Compare December 19, 2016 01:15
Copy link
Member

@rueckstiess rueckstiess left a comment

Choose a reason for hiding this comment

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

First of all: I can't reproduce the original issue from COMPASS-541 anymore on master, which was "filter lost when inserting a new document". So this may be a case of "gone away".

The following additional changes were introduced here:

  1. sort order is {_id: -1} now, instead of {_id: 1}
  2. after inserting a doc, the store resets and reloads a new set of documents.

1. was done so that a newly inserted document appears at the top and is visible to the user immediately. This only works a) until we introduce custom sort order, b) and only if the _id is larger than all previous _ids (which works for ObjectId but may not work for other types). It's also a deviation from shell behavior, which sorts in ascending order. I think the benefits are not strong enough here to justify the behavior change, especially when we let users sort on custom fields.

2. was done so that the count updates correctly in all cases and shows or doesn't show the new document correctly (as we cannot assume that the document matches the current query). However, it has the side-effect that it also resets the list of documents, and moves the scroll position back to the top. The user may have scrolled to a certain position for a reason and we should assume they wanted to remain there, since inserting documents is a modal action and should not change the screen state underneath the modal.

Determining on the client side if the new document matches the query or not is difficult however (although there are node modules that immitate the query matcher). So here I'm on the fence, but open to using this new behavior.

@samweaver, @durran any comments on this?

sort: [[ '_id', 1 ]],
// Default to reverse chronological order so newly inserted
// documents are shown at the top near the insert button
sort: [[ '_id', -1 ]],
Copy link
Member

Choose a reason for hiding this comment

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

While this has the side-effect of showing new documents at the top, it's also an unexpected behavior change from prior versions and users coming from the shell may find this unintuitive (because there the documents return in ascending order). Also, soon the user can set an explicit sort, so the problem would reoccur.

I prefer staying consistent with the shell behavior here. @samweaver, @durran any thoughts?

Choose a reason for hiding this comment

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

We should stay consistent with the shell and return ascending order. As you say, once we have sort order this doesn't matter anyway.

Choose a reason for hiding this comment

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

  1. Is interesting. The way that mongochef does this is to insert the new document to the bottom of the view, then jump the scroll to the bottom of the view. They don't update the count, they simply do "X documents + Y added". Where X is the original number returned by the query.

Choose a reason for hiding this comment

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

If we reset the store, can we call an action to jump to the bottom of the doc view? Once we have user defined sort, we detect -1 or 1 to decide whether to jump to bottom of view or not.

sort: [[ '_id', 1 ]],
// Default to reverse chronological order so newly inserted
// documents are shown at the top near the insert button
sort: [[ '_id', -1 ]],
Copy link
Member

Choose a reason for hiding this comment

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

see above.

Choose a reason for hiding this comment

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

As above.

@durran
Copy link
Member

durran commented Dec 19, 2016

I agree with @rueckstiess ' comments... I was under the impression we would introduce something like Sift and just check if the document matched the current filter or not before adding it to the list.

@pzrq
Copy link
Contributor Author

pzrq commented Dec 21, 2016

Pending feedback from @samweaver or designers about how Compass should behave, which may ultimately end up blocked on user-configurable sort (+skip/limit/project which is currently the story in COMPASS-412).

Going to close this for now as we have this PR and GitHub should retain the branch after deleting it, on the off-chance that this specific implementation ends up being how Compass should behave or if whoever picks up COMPASS-541 next decides to use it as inspiration to start on their fix.

@pzrq pzrq closed this Dec 21, 2016
@pzrq pzrq deleted the COMPASS-541-insert-plus-filter branch December 21, 2016 03:14
@samweaver-zz
Copy link

Left some comments.

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.

None yet

5 participants