fix: stabilize im server startup and p2p topic scans
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user