-
Notifications
You must be signed in to change notification settings - Fork 13
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
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f120daa
Optimizes wallet and block search
alfonsobries d852f90
typo
alfonsobries f75cf53
Optimize transaction search
alfonsobries 9b4d4a2
style: resolve style guide violations
alfonsobries 74f1a99
We can use private methods
alfonsobries a6b77bb
Search by height fix
alfonsobries f79d4e3
Validate the address only by the length
alfonsobries d4efa13
Accept uppercase for usernames
alfonsobries 8399167
style: resolve style guide violations
alfonsobries f6847b8
Update transaction search test
alfonsobries e953961
Update SearchPageTest.php
alfonsobries 03b7a45
Merge branch 'refactor/search-optimizations' of github.com:ArkEcosyst…
alfonsobries 8541eec
Update SearchPageTest.php
alfonsobries ef3c3ea
Update SearchPageTest.php
alfonsobries c4caabb
Better naming
alfonsobries d41bf29
Remove/rename unnecessary methods
alfonsobries 358bb68
typo
alfonsobries d5ceb6f
Remove deprecated scope
alfonsobries b363126
Merge branch 'deps-and-padding' of github.com:ArkEcosystem/explorer.a…
alfonsobries e69f7ca
wip
ItsANameToo d1f81fd
Merge branch 'deps-and-padding' of github.com:ArkEcosystem/explorer.a…
alfonsobries 15eb5e3
Refactor empty scopes
alfonsobries 656253b
Simplify query
alfonsobries bf81681
Merge branch 'deps-and-padding' into refactor/search-optimizations
ItsANameToo 5adf02e
style: resolve style guide violations
ItsANameToo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
final class SQLEnum | ||
{ | ||
const INT4_MAXVALUE = 2147483647; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models\Concerns; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
trait HasEmptyScope | ||
{ | ||
/** | ||
* Used to force a query with no results. | ||
*/ | ||
public function scopeEmpty(Builder $query): Builder | ||
{ | ||
return $query->whereRaw('false'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Services\Search\Traits; | ||
|
||
use App\Enums\SQLEnum; | ||
|
||
trait ValidatesTerm | ||
{ | ||
private function couldBeTransactionID(string $term): bool | ||
{ | ||
return $this->is64CharsHexadecimalString($term); | ||
} | ||
|
||
private function couldBeBlockID(string $term): bool | ||
{ | ||
return $this->is64CharsHexadecimalString($term); | ||
} | ||
|
||
private function couldBeAddress(string $term): bool | ||
{ | ||
return strlen($term) === 34; | ||
} | ||
|
||
private function couldBePublicKey(string $term): bool | ||
{ | ||
return strlen($term) === 66 && $this->isHexadecimalString($term); | ||
} | ||
|
||
/** | ||
* Check if the query can be a username | ||
* Regex source: https://github.com/ArkEcosystem/core/blob/4e149f039b59da97d224db1c593059dbc8e0f385/packages/core-api/src/handlers/shared/schemas/username.ts. | ||
* | ||
* @return bool | ||
*/ | ||
private function couldBeUsername(string $term): bool | ||
{ | ||
$regex = '/^[a-zA-Z0-9!@$&_.]+$/'; | ||
|
||
return strlen($term) >= 1 | ||
&& strlen($term) <= 20 | ||
&& preg_match($regex, $term, $matches) > 0; | ||
} | ||
|
||
private function couldBeHeightValue(string $term): bool | ||
{ | ||
$numericTerm = strval(filter_var($term, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND)); | ||
|
||
return $this->isOnlyNumbers($numericTerm) && $this->numericTermIsInRange($numericTerm); | ||
} | ||
|
||
private function is64CharsHexadecimalString(string $term): bool | ||
{ | ||
return $this->isOnlyNumbers($term) | ||
|| (strlen($term) === 64 && $this->isHexadecimalString($term)); | ||
} | ||
|
||
private function isOnlyNumbers(string $term): bool | ||
{ | ||
return ctype_digit($term); | ||
} | ||
|
||
private function isHexadecimalString(string $term): bool | ||
{ | ||
return ctype_xdigit($term); | ||
} | ||
|
||
/** | ||
* Validates that the numnber is smaller that the max size for a type integer | ||
* on pgsql. Searching for a bigger number will result in an SQL exception. | ||
* | ||
* @return bool | ||
*/ | ||
private function numericTermIsInRange(string $term): bool | ||
{ | ||
return floatval($term) <= SQLEnum::INT4_MAXVALUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above