mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
fix: resolve 6 medium issues from full go-review
- MED-1: Document soundboard channelID=0 server-wide permission intent - MED-2: Document os.Exit(0) in update handler skipping deferred cleanup - MED-3: Replace os.ReadFile/WriteFile with streaming io.Copy in backup restore to avoid loading entire DB into memory - MED-4: Add GetAllVoiceStates bulk query, eliminating N+1 per-channel queries in collectAllVoiceStates - MED-5: Wrap handlePatchSettings updates in a transaction for atomicity - MED-6: Add rows.Err() check after scan loop in getReactionsBatch - MED-9: Replace manual port-stripping in serverHost with net.SplitHostPort for correct IPv6 handling
This commit is contained in:
@@ -373,6 +373,9 @@ func (d *DB) getReactionsBatch(msgIDs []int64, requestingUserID int64) (map[int6
|
||||
ri.Me = me != 0
|
||||
result[msgID] = append(result[msgID], ri)
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, fmt.Errorf("getReactionsBatch rows: %w", rows.Err())
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,39 @@ func (d *DB) GetChannelVoiceStates(channelID int64) ([]VoiceState, error) {
|
||||
return states, nil
|
||||
}
|
||||
|
||||
// GetAllVoiceStates returns voice states across all voice channels in a single
|
||||
// query. Used at startup to build the ready payload without N+1 per-channel queries.
|
||||
func (d *DB) GetAllVoiceStates() ([]VoiceState, error) {
|
||||
rows, err := d.sqlDB.Query(
|
||||
`SELECT vs.user_id, vs.channel_id, u.username,
|
||||
vs.muted, vs.deafened, vs.speaking,
|
||||
vs.camera, vs.screenshare
|
||||
FROM voice_states vs
|
||||
JOIN users u ON u.id = vs.user_id
|
||||
ORDER BY vs.channel_id, vs.joined_at ASC`,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("GetAllVoiceStates: %w", err)
|
||||
}
|
||||
defer rows.Close() //nolint:errcheck
|
||||
|
||||
var states []VoiceState
|
||||
for rows.Next() {
|
||||
vs, scanErr := scanVoiceStateRow(rows)
|
||||
if scanErr != nil {
|
||||
return nil, fmt.Errorf("GetAllVoiceStates scan: %w", scanErr)
|
||||
}
|
||||
states = append(states, vs)
|
||||
}
|
||||
if rows.Err() != nil {
|
||||
return nil, fmt.Errorf("GetAllVoiceStates rows: %w", rows.Err())
|
||||
}
|
||||
if states == nil {
|
||||
states = []VoiceState{}
|
||||
}
|
||||
return states, nil
|
||||
}
|
||||
|
||||
// UpdateVoiceMute sets the muted field for the given user's voice state.
|
||||
// It is safe to call when the user is not in any channel (no-op).
|
||||
func (d *DB) UpdateVoiceMute(userID int64, muted bool) error {
|
||||
|
||||
Reference in New Issue
Block a user