From ea68b9de0a87cf90df4313bb6758756e75b34d30 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 16 Oct 2020 12:03:38 -0400 Subject: [PATCH 1/2] fix #1330 --- irc/accounts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/irc/accounts.go b/irc/accounts.go index f98eaada..6a2ddd60 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -1361,6 +1361,7 @@ func (am *AccountManager) Unregister(account string, erase bool) error { lastSeenKey := fmt.Sprintf(keyAccountLastSeen, casefoldedAccount) unregisteredKey := fmt.Sprintf(keyAccountUnregistered, casefoldedAccount) modesKey := fmt.Sprintf(keyAccountModes, casefoldedAccount) + realnameKey := fmt.Sprintf(keyAccountRealname, casefoldedAccount) var clients []*Client defer func() { @@ -1419,6 +1420,7 @@ func (am *AccountManager) Unregister(account string, erase bool) error { tx.Delete(joinedChannelsKey) tx.Delete(lastSeenKey) tx.Delete(modesKey) + tx.Delete(realnameKey) _, err := tx.Delete(vhostQueueKey) am.decrementVHostQueueCount(casefoldedAccount, err) From af8ed62de8578a298aefd02e000167b80aa2144e Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Fri, 16 Oct 2020 12:08:23 -0400 Subject: [PATCH 2/2] schema change for #1330 --- irc/database.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/irc/database.go b/irc/database.go index c2989a22..8b1c231c 100644 --- a/irc/database.go +++ b/irc/database.go @@ -24,7 +24,7 @@ const ( // 'version' of the database schema keySchemaVersion = "db.version" // latest schema of the db - latestDbSchema = "15" + latestDbSchema = "16" keyCloakSecret = "crypto.cloak_secret" ) @@ -812,6 +812,29 @@ func schemaChangeV14ToV15(config *Config, tx *buntdb.Tx) error { return nil } +// #1330: delete any stale realname records +func schemaChangeV15ToV16(config *Config, tx *buntdb.Tx) error { + prefix := "account.realname " + verifiedPrefix := "account.verified " + var keys []string + tx.AscendGreaterOrEqual("", prefix, func(key, value string) bool { + if !strings.HasPrefix(key, prefix) { + return false + } + acct := strings.TrimPrefix(key, prefix) + verifiedKey := verifiedPrefix + acct + _, verifiedErr := tx.Get(verifiedKey) + if verifiedErr != nil { + keys = append(keys, key) + } + return true + }) + for _, key := range keys { + tx.Delete(key) + } + return nil +} + func init() { allChanges := []SchemaChange{ { @@ -884,6 +907,11 @@ func init() { TargetVersion: "15", Changer: schemaChangeV14ToV15, }, + { + InitialVersion: "15", + TargetVersion: "16", + Changer: schemaChangeV15ToV16, + }, } // build the index