bito-code-review[bot] commented on PR #44017:
URL: https://github.com/apache/superset/pull/44017#issuecomment-5767136284
<!-- Bito Reply -->
The current implementation uses `g` to store the cache, which persists for
the duration of the application context. As you noted, this means the cache
survives across multiple requests within the same `app_context()`. To tie the
cache to the request lifetime specifically, you can store it on the
`flask.request` object instead of `g`. Since `flask.request` is only available
when `has_request_context()` is true, this naturally aligns with your existing
check.
**superset/subjects/utils.py**
```
if not has_request_context():
return _query_user_subject_ids(user_id)
# Store on the request object instead of g
cache: dict[int, list[int]] = getattr(request, "_user_subject_ids", {})
if not hasattr(request, "_user_subject_ids"):
request._user_subject_ids = cache
if user_id not in cache:
cache[user_id] = _query_user_subject_ids(user_id)
return list(cache[user_id])
```
--
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]