Skip to content

Conversation

@Piumal1999
Copy link

@Piumal1999 Piumal1999 commented Dec 22, 2025

Purpose

To fix wso2/api-manager#4581

Approach

Cherry picked from #3605

This was previously fixed with #3606, but the commit had been removed during the 4.9.x branch creation

If the path was not found, keep the cached value as -1, so it doesn't have to check the file multiple times

Testing

  1. Create an API without a thumbnail
  2. Call the following curl command to get the thumbnail.
curl -kv https://localhost:9443/api/am/devportal/v3/apis/f8c90a40-51f1-4ea2-b0eb-4c457cc7370b/thumbnail -u admin:admin
  1. Observe the correlation logs for SELECT REG_PATH_ID FROM REG_PATH ... queries before the fix and after the fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cache handling to store entries for unsuccessful path lookups, reducing redundant queries and enhancing performance when accessing non-existent paths repeatedly.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

Walkthrough

A single file modification to JDBCPathCache implementing negative caching: when a path lookup returns no results, the code now stores a cache entry with pathId value of -1 as a sentinel, preventing subsequent redundant database lookups for non-existent paths.

Changes

Cohort / File(s) Change Summary
Negative Cache Implementation
core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java
Cache "not found" query results by storing RegistryCacheEntry with pathId=-1 sentinel value for missing paths; reduces redundant database queries on subsequent lookups of non-existent paths

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify that pathId=-1 is a safe sentinel value and won't conflict with existing logic that checks or uses pathId
  • Confirm the negative cache entry persists correctly alongside positive hits
  • Check if there are callers that specifically handle or filter the -1 pathId value

Poem

🐰 A cache that remembers "not here,"
Saves queries that cost us dear,
With sentinel -1, the truth is told,
No more searching for paths of old! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description covers Purpose, Approach, and Testing sections but is missing several required template sections including Goals, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, and Learning. While the core intent is clear, consider completing the PR description template by adding the missing sections, particularly Automation tests, Security checks, Test environment, and Documentation to ensure comprehensive review coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: caching not found paths as -1 to reduce JDBC calls, which directly matches the code modification that adds negative cache entries.
Linked Issues check ✅ Passed The PR implementation directly addresses issue #4581 by reducing redundant JDBC queries when paths are not found through negative caching with -1 sentinel values.
Out of Scope Changes check ✅ Passed All changes are focused on the stated objective of reducing JDBC calls by caching not-found paths as -1 in JDBCPathCache.getPathID, with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1 N Not required

@Piumal1999 Piumal1999 marked this pull request as ready for review December 22, 2025 05:50
@Piumal1999
Copy link
Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

🧹 Nitpick comments (1)
core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java (1)

513-516: Consider adding debug logging for observability.

The past review suggested adding a log.debug() statement when caching the -1 sentinel. While not essential, this would improve observability when troubleshooting cache behavior or verifying the optimization is working as intended.

🔎 Optional: Add debug logging
 } else {
     //not found . set -1 in the cache as well for the path
+    if (log.isDebugEnabled()) {
+        log.debug("Path not found in database: " + path + ". Caching with ID -1.");
+    }
     RegistryCacheEntry e = new RegistryCacheEntry(-1);
     cache.put(key, e);
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 216a3d6 and c278777.

📒 Files selected for processing (1)
  • core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java
🔇 Additional comments (1)
core/org.wso2.carbon.registry.core/src/main/java/org/wso2/carbon/registry/core/jdbc/dao/JDBCPathCache.java (1)

513-516: Negative caching implementation looks correct.

The logic properly caches -1 as a sentinel for non-existent paths, which will effectively reduce redundant database queries for repeatedly requested missing resources (e.g., missing API thumbnails). The sentinel value is consistent with the method's existing return value, and the cache will be correctly updated if the path is later added via addEntry().

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.

2 participants