fix: stabilize im server startup and p2p topic scans

This commit is contained in:
richjohnrambo
2026-08-24 16:20:02 +08:00
parent e61058ec03
commit 07376c70e3
8 changed files with 124 additions and 30 deletions
+20
View File
@@ -996,6 +996,10 @@ func (a *adapter) UpgradeDb() error {
return err
}
if err := a.ensureMessageTopicSeqIndex(); err != nil {
return err
}
if a.version == adpVersion {
return nil
}
@@ -1004,6 +1008,22 @@ func (a *adapter) UpgradeDb() error {
strconv.Itoa(a.version) + " to " + strconv.Itoa(adpVersion) + " is not supported")
}
func (a *adapter) ensureMessageTopicSeqIndex() error {
const indexName = "messages_topic_seqid"
var count int
if err := a.db.QueryRow(
`SELECT COUNT(*) FROM information_schema.statistics
WHERE table_schema=DATABASE() AND table_name='im_messages' AND index_name=?`,
indexName).Scan(&count); err != nil {
return err
}
if count > 0 {
return nil
}
_, err := a.db.Exec("ALTER TABLE im_messages ADD UNIQUE INDEX messages_topic_seqid(topic, seqid)")
return err
}
func createIMNotificationTables(tx *sql.Tx) error {
_, err := tx.Exec(
`CREATE TABLE im_system_notifications(