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

Add prefix checking before displaying list of matched articles #593

Closed
wants to merge 2 commits into from
Closed

Add prefix checking before displaying list of matched articles #593

wants to merge 2 commits into from

Conversation

cz2h
Copy link

@cz2h cz2h commented Feb 18, 2020

Attempt to address the issue described in issue #184 .

Add an early return if either the follow conditions holds:

  • The search prefix input box is empty. (Which prevents loading search result after redirecting)
  • The dirEntry array is non-empty and is not the result from latest prefix search. (Will handle the empty array in the origin code)

@kelson42 kelson42 requested review from mossroy and Jaifroid and removed request for mossroy February 19, 2020 09:37
Copy link
Contributor

@mossroy mossroy left a comment

Choose a reason for hiding this comment

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

The implementation looked like a good idea at first sight.
But, second thought, I think it won't be reliable (and may introduce bugs) because comparing the first dirEntry url with the search field is not safe.
The current search implementation uses several "variants" of the search field to do the binary search with (and also first trims it). See function findDirEntriesWithPrefix of ZIMArchive. So we can not simply compare it. Doing a case insensitive comparison might cover most cases, but also could give false-positives.
Another problem is that the search algorithm might change in the future. For example to allow to search the string anywhere in the title, or even for full-text search. We won't be able to duplicate this logic here.

A proper fix for #184 (that could also cover #89 as a refactoring of #587) would be to pass a kind of state through all the callbacks, that could be compared with the expected state.
But it might be complicated to implement.
This state could be an object with 2 properties : the type of current action (searching, or going to an article), and an id for the current action (search prefix for a search, article url for an article). Or maybe this state might even be an integer, incremented on each user action. This needs to be thought about more deeply.

…st async action that could result in false display
@cz2h
Copy link
Author

cz2h commented Feb 25, 2020

Thanks for the hints in addressing this issue.

I managed to use the latestUserAsynAction as the state to store user's latest action that might cause false displayed. I compare the state to perform early return in readArticle and searchDirEntriesFromPrefix since these are the two callbacks that may cause false displays.

The only problem I found while testing is after searching and clicking an article, the search result might come back too fast and block the action of going to the clicked article but I am assuming this rarely happens.

Copy link
Contributor

@mossroy mossroy left a comment

Choose a reason for hiding this comment

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

The way to implement that might be good, but it lacks testing and re-reading.
Please take more time to review/test your changes before asking for our reviews, else I'll give up.

In ServiceWorker mode, the main page does not show up, and any attempt to open an article gives a :

isDirEntryExpectedToBeDisplayed is not defined

There also are many typos in the comments.
More minor remarks :

  • Regarding the wording, I think you should use the word "async" instead of "asyn". The function isThisCallbackExpectedToBePerformed would have a more meaningful name with something like isTheLatestAction
  • in the functions that get the new action as a parameter, I would have put it as the last parameter instead of the first. Because it's not the most important parameter, and might be optional : if no action is passed, we don't do any check (like before)

To help testing, you might introduce delays in all the async actions you try to cover, with something like setTimeout. You could even commit it, to help our testing too. And you would remove these delays before the merging

@mossroy
Copy link
Contributor

mossroy commented Mar 22, 2020

@zengchu2 : do you intend to finalize this PR?

@kelson42
Copy link
Collaborator

No feedback from the developer. I think this PR will have to be closed or finished by someone else.

@mossroy
Copy link
Contributor

mossroy commented Apr 27, 2020

Closing this PR. The branch should be kept because I think the implementation was on the right track anyway

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.

3 participants