-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce calls to Mattermost server by caching replies #513
Conversation
b7f3c7c
to
5c7d483
Compare
5c7d483
to
c0776e7
Compare
Memory usage is pretty good and remains quite constant. This is with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to use the https://github.com/hashicorp/golang-lru which handles the cleanup and locking for you.
You also don't need the maps then.
cache := lru.New(30)
var (
replyMessage string
ok bool
)
if replyMessage,ok = cache.Get(parentID); !ok {
do the GetPost stuff
...
}
This removes all the complexity of maps/counters/locking and lets the 3rd party library deal with it.
The keys should be unique enough to just put them in the main cache instead of mapping it per channel.
WDYT ?
ff5bf93
to
032f0b6
Compare
Good call/advice, I've updated the PR switching to using the 3rd party HashiCorp LRU library. I think the advantage of using per-channel caching is that a channel that sees less activity would not have cached entries pushed out of the cache because of having channels with more activity. But yeah, this simplifies the code (less code, less bugs and all that), we can further tune the cache size if needed. |
032f0b6
to
1d7f1f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Haven't tested it yet though. But fine to merge if you battletested it, otherwise I'll test tomorrow
Thanks, I'm running with it now but not in a rush to have it landed so happy to wait for additional testing 👍 |
Replaces #508. For each message that's a reply to a thread, we make an extra API call to get the parent message to use as reply text. This caches that to reduce requests to the MM server.