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

BE-636 | Fix search bug #584

Merged
merged 1 commit into from
Dec 4, 2024
Merged

BE-636 | Fix search bug #584

merged 1 commit into from
Dec 4, 2024

Conversation

deividaspetraitis
Copy link
Collaborator

@deividaspetraitis deividaspetraitis commented Dec 4, 2024

Fixes a bug when searching pool by pair of tokens for /pools endpoint

Summary by CodeRabbit

  • New Features

    • Improved search functionality for pools, allowing for more flexible matching criteria.
    • Enhanced handling of pool metadata for better retrieval during searches.
  • Bug Fixes

    • Resolved issues with search string formatting, ensuring case-insensitive comparisons without spaces.

Fixes a bug when searching pool by pair of tokens for /pools endpoint
@deividaspetraitis deividaspetraitis added the A:backport/v28.x Backport to v28.x branch label Dec 4, 2024
@deividaspetraitis deividaspetraitis self-assigned this Dec 4, 2024
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request focus on refining the handling of pool metadata and search functionalities within the pools_usecase.go file. Key modifications include replacing the method for retrieving pool denominations and enhancing the search capabilities by normalizing the search string. The core structure and logic of the poolsUseCase remain unchanged, ensuring that existing functionalities are preserved while improving the usability of the search features.

Changes

File Path Change Summary
pools/usecase/pools_usecase.go - Replaced pool.GetPoolDenoms() with pool.GetSQSPoolModel().PoolDenoms in search functions.
- Updated filterPartialMatchSearch to remove spaces from the search string for case-insensitive comparisons.

Possibly related PRs

Suggested reviewers

  • cryptomatictrader
  • p0mvn

🐇 "In the pools where we hop and play,
Searching for treasures, come what may.
With spaces trimmed and denoms in sight,
Our quest for the best pools feels just right!
So let’s leap forward, with joy and cheer,
For every search brings us closer, my dear!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
pools/usecase/pools_usecase.go (1)

448-453: Consider caching normalized strings

While the search logic is correct, we could optimize performance by normalizing strings once at the beginning of the function rather than in each comparison.

Here's a suggested optimization:

 var humanDenoms []string
 var poolNameByDenom string
 var coinnames []string
+var normalizedCoinNames []string
 
 for _, denom := range pool.GetSQSPoolModel().PoolDenoms {
     token, err := tokenMetadataHolder.GetMetadataByChainDenom(denom)
     if err != nil {
         continue
     }
     coinnames = append(coinnames, token.Name)
+    normalizedCoinNames = append(normalizedCoinNames, strings.ToLower(token.Name))
     humanDenoms = append(humanDenoms, token.HumanDenom)
 }
 
 poolNameByDenom = strings.Join(humanDenoms, "/")
+normalizedPoolName := strings.ToLower(poolNameByDenom)
 search = strings.Replace(strings.ToLower(search), " ", "", -1)
 
-if strings.Contains(strings.ToLower(poolNameByDenom), search) {
+if strings.Contains(normalizedPoolName, search) {
     return true
 }
 
-for _, coinName := range coinnames {
-    if strings.Contains(strings.ToLower(coinName), search) {
+for _, normalizedName := range normalizedCoinNames {
+    if strings.Contains(normalizedName, search) {
         return true
     }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 16e9207 and faf33bc.

📒 Files selected for processing (1)
  • pools/usecase/pools_usecase.go (3 hunks)
🔇 Additional comments (3)
pools/usecase/pools_usecase.go (3)

408-408: LGTM: Direct access to pool denominations

The change from GetPoolDenoms() to direct access via GetSQSPoolModel().PoolDenoms provides a more reliable way to retrieve pool denominations.


Line range hint 435-445: LGTM: Consistent pool denomination access

The change maintains consistency with the previous modification and properly constructs the pool name from human denominations.


446-447: LGTM: Improved search string normalization

The addition of space removal and case normalization makes the search more user-friendly and robust. This change will help users find pools regardless of spacing or case in their search terms.

@deividaspetraitis deividaspetraitis merged commit 1427db0 into v27.x Dec 4, 2024
9 checks passed
@deividaspetraitis deividaspetraitis deleted the BE-636-search-bug-fix branch December 4, 2024 10:44
mergify bot pushed a commit that referenced this pull request Dec 4, 2024
Fixes a bug when searching pool by pair of tokens for /pools endpoint

(cherry picked from commit 1427db0)
deividaspetraitis added a commit that referenced this pull request Dec 4, 2024
Fixes a bug when searching pool by pair of tokens for /pools endpoint

(cherry picked from commit 1427db0)

Co-authored-by: Deividas Petraitis <hi@deividaspetraitis.lt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:backport/v28.x Backport to v28.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant