42wim / matterircd

Connect to your mattermost or slack using your IRC-client of choice.
MIT License
294 stars 60 forks source link

Support saving last viewed at state for multiple users #425

Closed hloeung closed 2 years ago

hloeung commented 3 years ago

matterircd supports multiple users so we save separate last viewed at state files for each user. We also only load them after a user has logged in rather than on start up.

42wim commented 3 years ago

I'm thinking that putting the info in 1 file instead of a file for each user is cleaner? WDYT ?

hloeung commented 3 years ago

I'm thinking that putting the info in 1 file instead of a file for each user is cleaner? WDYT ?

But then it would have to keep a global data structure instead of in NewUserBridge() and synchronize between the go routines when writing / saving the state file, IIUC.

42wim commented 3 years ago

I don't think it's a good idea to have multiple state files, we can do this in one file :-) but yes, you'd have some more locking issues then, you should only have one writer that writes the file using channels.

But as we're putting more stuff on disk what do you think about using boltdb as k/v store for this instead. You can instantiate one global writer so you don't need to do the locking yourself.

hloeung commented 3 years ago

Ah sure, I'll take a look at boltdb or something similar so that state files for multiple users are all contained within the one file on disk.

hloeung commented 3 years ago

@42wim , converted to using Bolt. It's also backwards compatible loading the existing values and then cleaning it up:

INFO[2021-06-27T14:28:44+10:00] Running version 0.24.3-dev                    module=matterircd
INFO[2021-06-27T14:28:44+10:00] WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.  module=matterircd
WARN[2021-06-27T14:28:44+10:00] Found old last viewed at state file, renaming to .migrated  module=matterircd
INFO[2021-06-27T14:28:44+10:00] Listening on 127.0.0.1:6697                   module=matterircd
INFO[2021-06-27T14:28:46+10:00] New connection: 127.0.0.1:49584               module=matterircd
loggerlevel: info
INFO[2021-06-27T14:29:01+10:00] login as hloeung (team: myteam) on mymattermostserver.local
[2021-06-27T14:29:02+10:00]  INFO matterclient: Found version 5.33.3.5.33.3.41edc0d55bd344e85da75fededb08bee.true
[2021-06-27T14:29:05+10:00]  INFO matterclient: found 686 users in team myteam
INFO[2021-06-27T14:29:07+10:00] login succeeded
WARN[2021-06-27T14:29:07+10:00] Found old last viewed at state file, loading and removing  module=matterircd
INFO[2021-06-27T14:29:07+10:00] Loaded lastViewedAt from 2021-06-26 09:05:47 +1000 AEST  module=matterircd
INFO[2021-06-27T14:29:16+10:00] Replaying msgs for hloeung for #channel1 (okgji...) since 2021-06-26 09:18:34 (stored)  module=matterircd
INFO[2021-06-27T14:29:17+10:00] Replaying msgs for hloeung for #channel2 (1tq37...) since 2021-06-26 10:28:19 (stored)  module=matterircd
INFO[2021-06-27T14:29:17+10:00] Replaying msgs for hloeung for #channel3 (ymnb5...) since 2021-06-26 10:06:49 (stored)  module=matterircd
INFO[2021-06-27T14:29:18+10:00] Replaying msgs for hloeung for #channel4 (64ynn...) since 2021-06-26 09:14:24 (stored)  module=matterircd
INFO[2021-06-27T14:29:21+10:00] Replaying msgs for hloeung for #channel5 (uw577...) since 2021-06-26 10:45:26 (server)  module=matterircd
INFO[2021-06-27T14:29:22+10:00] Replaying msgs for hloeung for #channel6 (53bct...) since 2021-06-26 17:33:18 (stored)  module=matterircd
INFO[2021-06-27T14:29:22+10:00] Replaying msgs for hloeung for #channel7 (c38ws...) since 2021-06-26 10:07:03 (stored)  module=matterircd
42wim commented 2 years ago

Seems I overlooked this PR :( Thanks for your work @hloeung 👍

hloeung commented 2 years ago

Thank you @42wim !