Limit the backlog of chat messages to recent messages. For #47
This commit is contained in:
parent
aebbce4b76
commit
a277012650
@ -80,5 +80,21 @@ func GetMessages() []models.ChatMessage {
|
|||||||
return []models.ChatMessage{}
|
return []models.ChatMessage{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _server.Messages
|
return getRecentMessages()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getRecentMessages() []models.ChatMessage {
|
||||||
|
if len(_server.Messages) < 100 {
|
||||||
|
return _server.Messages
|
||||||
|
}
|
||||||
|
|
||||||
|
maxAgeInHours := float64(2)
|
||||||
|
messages := make([]models.ChatMessage, 0)
|
||||||
|
for _, message := range _server.Messages {
|
||||||
|
if time.Since(message.Timestamp).Hours() < maxAgeInHours {
|
||||||
|
messages = append(messages, message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,8 @@ func addMessage(message models.ChatMessage) {
|
|||||||
func getChatHistory() []models.ChatMessage {
|
func getChatHistory() []models.ChatMessage {
|
||||||
history := make([]models.ChatMessage, 0)
|
history := make([]models.ChatMessage, 0)
|
||||||
|
|
||||||
rows, err := _db.Query("SELECT * FROM messages WHERE visible = 1")
|
// Get all messages sent within the past day
|
||||||
|
rows, err := _db.Query("SELECT * FROM messages WHERE visible = 1 AND datetime(timestamp) >=datetime('now', '-1 Day')")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user