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.
|
||||
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.
|
||||
result := DB.Where(
|
||||
"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 (
|
||||
cachedChatStatistics *ChatStatistics
|
||||
chatStatisticsMu sync.RWMutex
|
||||
|
@ -61,13 +68,9 @@ func DoCheckBareRTC() {
|
|||
log.Info("Refresh BareRTC")
|
||||
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 {
|
||||
log.Error("WatchBareRTC: couldn't make request: %s", err)
|
||||
cachedChatStatistics = nil
|
||||
SetChatStatistics(nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,11 +81,11 @@ func DoCheckBareRTC() {
|
|||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Error("WatchBareRTC: request error: %s", err)
|
||||
cachedChatStatistics = nil
|
||||
SetChatStatistics(nil)
|
||||
return
|
||||
} else if res.StatusCode != http.StatusOK {
|
||||
log.Error("WatchBareRTC: didn't get expected 200 OK from statistics endpoint, instead got: %s", res.Status)
|
||||
cachedChatStatistics = nil
|
||||
SetChatStatistics(nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -95,6 +98,6 @@ func DoCheckBareRTC() {
|
|||
return
|
||||
}
|
||||
|
||||
cachedChatStatistics = &cs
|
||||
SetChatStatistics(&cs)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user