Merge branch releases/maplru into release#298
Conversation
Hanssen0
commented
Aug 29, 2025
- I have read the Contributing Guidelines
|
✅ Deploy Preview for liveccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for docsccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for appccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Summary of Changes
Hello @Hanssen0, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on enhancing the stability and reliability of the core caching infrastructure within the project. It includes a significant refactor of the Least Recently Used (LRU) cache, which resolves a critical bug, and introduces new tests to validate the cache's behavior. Additionally, it propagates these core updates across the entire codebase through routine version synchronization.
Highlights
- LRU Cache Refactor and Bug Fix: The core LRU cache implementation (
MapLru) has been refactored for improved correctness and robustness, specifically addressing an issue whereClientCacheMemory.findCellscould get stuck in an infinite loop. - Enhanced Test Coverage: New and comprehensive unit tests have been added for both the
MapLrucache and theClientCacheMemoryto ensure the reliability and proper functioning of the caching mechanisms. - Cascading Version Updates: Multiple dependent packages across the monorepo have received version bumps to align with the updated
@ckb-ccc/corepackage, ensuring compatibility and leveraging the latest improvements.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
✅ Deploy Preview for apiccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Code Review
This pull request primarily refactors the MapLru implementation to be more robust and to fix a potential infinite loop in ClientCacheMemory.findCells. The new implementation separates storage from LRU logic, which is a good pattern. It also adds comprehensive tests for the new MapLru and for ClientCacheMemory.
My review includes one suggestion to improve code clarity by adding explicit return types to the methods in MapLru for consistency. Overall, the changes are a significant improvement.
| override get(key: K) { | ||
| if (!super.has(key)) { | ||
| return undefined; | ||
| return; | ||
| } | ||
|
|
||
| const value = super.get(key) as V; | ||
| this.lru.delete(key); | ||
| this.lru.add(key); | ||
|
|
||
| // Move to most-recently-used position | ||
| super.delete(key); | ||
| super.set(key, value); | ||
|
|
||
| return value; | ||
| return super.get(key); | ||
| } | ||
|
|
||
| /** | ||
| * Inserts a new value into the cache, or updates an existing value. | ||
| * | ||
| * If the key is already present in the cache, it is first deleted so that the re-insertion | ||
| * moves it to the most-recently-used position. | ||
| * If the cache is over capacity after the insertion, the least recently used entry is evicted. | ||
| * | ||
| * @param key The key of the value to insert or update. | ||
| * @param value The value to associate with the key. | ||
| * @returns This MapLru instance. | ||
| * Adds or updates a key-value pair in the cache and marks the key as recently used. | ||
| * If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted. | ||
| * @param key - The key of the element to add or update. | ||
| * @param value - The value of the element to add or update. | ||
| * @returns The `MapLru` instance. | ||
| */ | ||
| override set(key: K, value: V): this { | ||
| // Delete and re-insert to move key to the end (most-recently-used) | ||
| super.delete(key); | ||
| override set(key: K, value: V) { | ||
| super.set(key, value); | ||
|
|
||
| // Evict oldest if over capacity | ||
| if (super.size > this.capacity) { | ||
| const oldestKey = super.keys().next().value!; | ||
| super.delete(oldestKey); | ||
| } | ||
| this.lru.delete(key); | ||
| this.lru.add(key); | ||
|
|
||
| // Evict the oldest entry if capacity is exceeded. | ||
| if (this.lru.size > this.capacity) { | ||
| const oldestKey = this.lru.keys().next().value!; | ||
| this.delete(oldestKey); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Removes the specified element from the cache. | ||
| * @param key - The key of the element to remove. | ||
| * @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist. | ||
| */ | ||
| override delete(key: K): boolean { | ||
| if (!super.delete(key)) { | ||
| return false; | ||
| } | ||
|
|
||
| this.lru.delete(key); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Removes all key-value pairs from the cache. | ||
| */ | ||
| override clear() { | ||
| super.clear(); | ||
| this.lru.clear(); | ||
| } |
There was a problem hiding this comment.
For better code clarity and to maintain consistency with the overridden Map methods and the delete method in this class, it's a good practice to add explicit return types to the get, set, and clear methods. This makes the method signatures more explicit and self-documenting.
override get(key: K): V | undefined {
if (!super.has(key)) {
return;
}
this.lru.delete(key);
this.lru.add(key);
return super.get(key);
}
/**
* Adds or updates a key-value pair in the cache and marks the key as recently used.
* If setting a new key causes the cache to exceed its capacity, the least recently used item is evicted.
* @param key - The key of the element to add or update.
* @param value - The value of the element to add or update.
* @returns The `MapLru` instance.
*/
override set(key: K, value: V): this {
super.set(key, value);
this.lru.delete(key);
this.lru.add(key);
// Evict the oldest entry if capacity is exceeded.
if (this.lru.size > this.capacity) {
const oldestKey = this.lru.keys().next().value!;
this.delete(oldestKey);
}
return this;
}
/**
* Removes the specified element from the cache.
* @param key - The key of the element to remove.
* @returns `true` if an element in the `MapLru` object existed and has been removed, or `false` if the element does not exist.
*/
override delete(key: K): boolean {
if (!super.delete(key)) {
return false;
}
this.lru.delete(key);
return true;
}
/**
* Removes all key-value pairs from the cache.
*/
override clear(): void {
super.clear();
this.lru.clear();
}