Eagles-DevOps / MiniTwit

2 stars 1 forks source link

Naive caching of username/ID mapping #220

Open danielgron opened 2 months ago

danielgron commented 2 months ago

We have a lot of calls mapping id and username

userid, := db.Get_user_id(username)

This means an extra DB call taking up a connection slot and using time for handling the request.

Since ID/Username mapping never changes we can have an incredibly naive caching in memory with a map of userIds<string,int> that we fill up on startup / adding users. Then we can check that first and only do db call in case we don't have it in cache.

rasmus-bn commented 2 months ago

Lest cache the username in the session so we dont need to store it in the ram of the webserver

danielgron commented 2 months ago

I like that, but just realized that only works for the web server and not the api, so this still has merit