Minor quick fixes
This commit is contained in:
parent
2682512dd3
commit
26d2bc98f1
|
@ -210,6 +210,11 @@ func (t *Thread) Save() error {
|
||||||
|
|
||||||
// Delete a thread and all of its comments.
|
// Delete a thread and all of its comments.
|
||||||
func (t *Thread) Delete() error {
|
func (t *Thread) Delete() error {
|
||||||
|
// Unlink the parent comment from the thread to resolve a foreign key constraint in Postgres.
|
||||||
|
if result := DB.Model(&Thread{}).Where("id = ?", t.ID).Update("comment_id", nil); result.Error != nil {
|
||||||
|
return fmt.Errorf("Thread.Delete: couldn't unlink parent comment: %s", result.Error)
|
||||||
|
}
|
||||||
|
|
||||||
// Remove all comments.
|
// Remove all comments.
|
||||||
result := DB.Where(
|
result := DB.Where(
|
||||||
"table_name = ? AND table_id = ?",
|
"table_name = ? AND table_id = ?",
|
||||||
|
|
|
@ -34,6 +34,13 @@ func GetChatStatistics() ChatStatistics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetChatStatistics updates the cached chat statistics, holding a write lock briefly.
|
||||||
|
func SetChatStatistics(stats *ChatStatistics) {
|
||||||
|
chatStatisticsMu.Lock()
|
||||||
|
defer chatStatisticsMu.Unlock()
|
||||||
|
cachedChatStatistics = stats
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cachedChatStatistics *ChatStatistics
|
cachedChatStatistics *ChatStatistics
|
||||||
chatStatisticsMu sync.RWMutex
|
chatStatisticsMu sync.RWMutex
|
||||||
|
@ -61,13 +68,9 @@ func DoCheckBareRTC() {
|
||||||
log.Info("Refresh BareRTC")
|
log.Info("Refresh BareRTC")
|
||||||
req, err := http.NewRequest(http.MethodGet, config.Current.BareRTC.URL+"/api/statistics", nil)
|
req, err := http.NewRequest(http.MethodGet, config.Current.BareRTC.URL+"/api/statistics", nil)
|
||||||
|
|
||||||
// Lock the cached statistics.
|
|
||||||
chatStatisticsMu.Lock()
|
|
||||||
defer chatStatisticsMu.Unlock()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("WatchBareRTC: couldn't make request: %s", err)
|
log.Error("WatchBareRTC: couldn't make request: %s", err)
|
||||||
cachedChatStatistics = nil
|
SetChatStatistics(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +81,11 @@ func DoCheckBareRTC() {
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("WatchBareRTC: request error: %s", err)
|
log.Error("WatchBareRTC: request error: %s", err)
|
||||||
cachedChatStatistics = nil
|
SetChatStatistics(nil)
|
||||||
return
|
return
|
||||||
} else if res.StatusCode != http.StatusOK {
|
} else if res.StatusCode != http.StatusOK {
|
||||||
log.Error("WatchBareRTC: didn't get expected 200 OK from statistics endpoint, instead got: %s", res.Status)
|
log.Error("WatchBareRTC: didn't get expected 200 OK from statistics endpoint, instead got: %s", res.Status)
|
||||||
cachedChatStatistics = nil
|
SetChatStatistics(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +98,6 @@ func DoCheckBareRTC() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedChatStatistics = &cs
|
SetChatStatistics(&cs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user