Skip to content

Conversation

@warcholjakub
Copy link
Collaborator

Summary

Implements per-user presentation compiler (PC) caching. Each user (anonymous or authenticated) can now have at most one presentation compiler instance.

Key Changes

  • Client-side UUID generation: Added LocalStorage.getOrCreateClientUuid() to generate and persist UUIDs for anonymous users.
  • User identification: Authenticated users use their GitHub login, anonymous users use localStorage UUID.
  • Cache key modification: Changed cache from Cache[IO, ScastieMetalsOptions, PC] to Cache[IO, (String, ScastieMetalsOptions), PC] where String is the user UUID.
  • Per-user PC replacement: When a user requests a PC with different configuration, the old PC is automatically removed and replaced.

@warcholjakub warcholjakub requested a review from rochala November 21, 2025 16:58
setMetalsStatus: MetalsStatus ~=> Callback,
dependencies: Set[ScalaDependency])
dependencies: Set[ScalaDependency],
user: Option[User])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd just always generate random uuid for client, what is more. I think that you can generate it when someone enters the website and dont store it in local storage

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay

* @param userUuid - unique identifier for the user
* @param newConfiguration - the new configuration being requested
*/
private def findAndRemoveOldPCForUser(userUuid: String, newConfiguration: ScastieMetalsOptions): IO[Unit] =
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that we don't need to do this ? Cache entries have 5 min expiration time. I'm also not sure how it is implemented underneath. Is key.cache blocking whole access to the cache ? Is it non-blocking ? If it is non blocking how it will behave when during the cleanup we send another new request from same user and different config. Concurrency is hard. If I were you I'd drop this method and just leave it up to the cache

Add UUID-based user identification to limit each user (anonymous or authenticated) to one presentation compiler at a time. Anonymous users get a persistent UUID stored in localStorage, while authenticated users use their GitHub login as identifier.
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