SEPURI-SAI-KRISHNA opened a new pull request, #42409:
URL: https://github.com/apache/superset/pull/42409
### SUMMARY
`LRUCache#set` decided whether to evict using only the size check:
```ts
if (this.cache.size >= this.capacity) { /* evict oldest */ }
this.cache.set(key, value);
```
Overwriting a key that is already in the cache does not increase the entry
count, so no eviction is needed — but the check does not test for presence,
so an unrelated entry is dropped. With capacity 2:
```js
cache.set('a', 'a');
cache.set('b', 'b');
cache.set('b', 'b2'); // evicts 'a'; size falls to 1
```
Where this surfaces: `getRecentActivityObjs` (`src/views/CRUD/utils.tsx`)
builds a `lruCache(6)` keyed on `item_url` to de-duplicate the welcome page's
"Recently viewed" list. Because repeat views of the same item hit the
overwrite path, each duplicate silently discards a distinct entry, so the
list
can render fewer than 6 items.
Two changes:
- Skip eviction when the key is already present.
- `delete` before `set` for an existing key, so a write refreshes recency.
`Map#set` keeps the original insertion position for existing keys, and
`get`
already refreshes on read, so `set` not doing so was inconsistent.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not a visual change in itself. On the welcome page, "Recently viewed" could
previously show fewer than the intended 6 entries when the same dashboard or
chart appeared more than once in the recent-activity payload.
### TESTING INSTRUCTIONS
```bash
cd superset-frontend
npm run test -- packages/superset-ui-core/test/utils/lruCache.test.ts
```
Two tests are added:
- `overwriting an existing key does not evict another entry`
- `overwriting an existing key refreshes its recency`
The first is the regression test: revert the change and it fails with
`size Expected: 2, Received: 1`. The second documents the recency contract
(it happens to pass on the old code too, since the buggy eviction
coincidentally produced the same order in that particular scenario).
Consumers verified unaffected:
```bash
npm run test -- src/views/CRUD src/SqlLab/components/QueryAutoRefresh
```
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]