diff --git a/core/chat/persistence.go b/core/chat/persistence.go index cfc9c336c..ad4ab6264 100644 --- a/core/chat/persistence.go +++ b/core/chat/persistence.go @@ -289,7 +289,7 @@ func GetChatModerationHistory() []interface{} { // GetChatHistory will return all the chat messages suitable for returning as user-facing chat history. func GetChatHistory() []interface{} { // Get all visible messages - query := fmt.Sprintf("SELECT messages.id,messages.user_id, messages.body, messages.title, messages.subtitle, messages.image, messages.link, messages.eventType, messages.hidden_at, messages.timestamp, users.display_name, users.display_color, users.created_at, users.disabled_at, users.previous_names, users.namechanged_at, users.authenticated_at, users.scopes, users.type FROM messages LEFT JOIN users ON messages.user_id = users.id WHERE hidden_at IS NULL AND disabled_at IS NULL ORDER BY timestamp DESC LIMIT %d", maxBacklogNumber) + query := fmt.Sprintf("SELECT messages.id, messages.user_id, messages.body, messages.title, messages.subtitle, messages.image, messages.link, messages.eventType, messages.hidden_at, messages.timestamp, users.display_name, users.display_color, users.created_at, users.disabled_at, users.previous_names, users.namechanged_at, users.authenticated_at, users.scopes, users.type FROM users JOIN messages ON users.id = messages.user_id WHERE hidden_at IS NULL AND disabled_at IS NULL ORDER BY timestamp DESC LIMIT %d", maxBacklogNumber) m := getChat(query) // Invert order of messages diff --git a/core/data/persistence.go b/core/data/persistence.go index 8a02f1799..cd182f6e4 100644 --- a/core/data/persistence.go +++ b/core/data/persistence.go @@ -118,7 +118,7 @@ func (ds *Datastore) Setup() { "key" string NOT NULL PRIMARY KEY, "value" BLOB, "timestamp" DATE DEFAULT CURRENT_TIMESTAMP NOT NULL - );` + );CREATE INDEX IF NOT EXISTS messages_timestamp_index ON messages(timestamp);` stmt, err := ds.DB.Prepare(createTableSQL) if err != nil {