diff options
author | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-06-03 07:20:03 +0300 |
---|---|---|
committer | Bohdan Horbeshko <bodqhrohro@gmail.com> | 2023-06-03 07:20:03 +0300 |
commit | 9a84e9a8b6b7a6f953301e54f19cdf4be73592e1 (patch) | |
tree | 33e96558211827f696868815222e2d36abbd8fcb /xmpp/component.go | |
parent | 8663a29e157aae6e68cc880a86b3a666da37bfc9 (diff) |
Store message ids in Badger DB
Diffstat (limited to 'xmpp/component.go')
-rw-r--r-- | xmpp/component.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/xmpp/component.go b/xmpp/component.go index 0f23d50..f0c481d 100644 --- a/xmpp/component.go +++ b/xmpp/component.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "dev.narayana.im/narayana/telegabber/badger" "dev.narayana.im/narayana/telegabber/config" "dev.narayana.im/narayana/telegabber/persistence" "dev.narayana.im/narayana/telegabber/telegram" @@ -38,7 +39,7 @@ var sizeRegex = regexp.MustCompile("\\A([0-9]+) ?([KMGTPE]?B?)\\z") // NewComponent starts a new component and wraps it in // a stream manager that you should start yourself -func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.StreamManager, *xmpp.Component, error) { +func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig, idsPath string) (*xmpp.StreamManager, *xmpp.Component, error) { var err error gateway.Jid, err = stanza.NewJid(conf.Jid) @@ -53,6 +54,8 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea } } + gateway.IdsDB = badger.IdsDBOpen(idsPath) + tgConf = tc if tc.Content.Quota != "" { @@ -163,6 +166,8 @@ func heartbeat(component *xmpp.Component) { // it would be resolved on the next iteration SaveSessions() } + + gateway.IdsDB.Gc() } } @@ -240,6 +245,9 @@ func Close(component *xmpp.Component) { // save sessions SaveSessions() + // flush the ids database + gateway.IdsDB.Close() + // close stream component.Disconnect() } |