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

refactor: search optimizations #791

Merged
merged 25 commits into from
Jun 10, 2021

Conversation

alfonsobries
Copy link
Member

@alfonsobries alfonsobries commented Jun 4, 2021

Summary

https://app.clickup.com/t/kz8hz2

Refactor the search-related classes to prevent unnecessary queries according to the search term for faster searches.

Checklist

  • Documentation (if necessary)
  • Tests (if necessary)
  • Ready to be merged

@alfonsobries alfonsobries marked this pull request as ready for review June 4, 2021 20:46
@alfonsobries alfonsobries changed the title [WIP] refactor: search optimizations refactor: search optimizations Jun 4, 2021
*/
public function scopeEmpty(Builder $query): Builder
{
return $query->whereNull('id');
Copy link
Member

Choose a reason for hiding this comment

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

is this the preferred way to return an empty result? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

hmm I see now that you use these in else statements, but wouldn't it suffice to not create a query if the if does not hit? e.g. here https://github.com/ArkEcosystem/explorer.ark.io/pull/791/files#diff-b59c182bce7d848ab8acb5b96e78d56938d6ac1bf6128802f73eee834b288199R35

Copy link
Member Author

@alfonsobries alfonsobries Jun 8, 2021

Choose a reason for hiding this comment

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

@ItsANameToo the problem is that if the empty scope is not applied it will return all the blocks, so if my search query is, let's say, a random string like "asdfg" it incorrectly will show all the blocks since the resulted query will be select * from "blocks". What I'm doing is basically replacing the select * from "blocks" where lower(id) = "asdfg" that takes approx 4s (and we know will not return any result) for a simple select * from "blocks" where id = null that just takes a few milliseconds and also returns empty results

The problem is that I cannot just return an empty array, I still need a query builder instance since more conditions may apply, in other words, the query is just ensuring that we will not find any blocks by the given id by doing the simplest as fastest query I found. Since the following conditions (that may or not may apply) are orWhere still will be possible to find results, for example, if the query is a valid wallet username.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ItsANameToo regarding whether that's the preferred way I consider different solutions and I didn't find a better one. I'll revisit this PR in a moment to see if I come up with a cleaner alternative.

} else {
// Forces empty results when it has a term but not possible
// block ID
$query->empty();
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to force empty here?

Copy link
Member Author

Choose a reason for hiding this comment

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

See comment above

@alfonsobries
Copy link
Member Author

alfonsobries commented Jun 8, 2021

@ItsANameToo didn't change the solution of empty scopes that are still open for discussion but refactored the empty scopes for something much cleaner. See: 15eb5e3

@alexbarnsley alexbarnsley self-assigned this Jun 9, 2021
@ItsANameToo
Copy link
Member

added a clickup task to reconsider those empty scopes https://app.clickup.com/t/m97mgv . Still feels like there's a better approach but at this time I cannot think of one.

@ItsANameToo ItsANameToo merged commit 6127784 into deps-and-padding Jun 10, 2021
@ItsANameToo ItsANameToo deleted the refactor/search-optimizations branch June 10, 2021 08:16
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.

4 participants