ENV Update
This commit is contained in:
@@ -11,27 +11,61 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxActivityLogEntries = 400
|
||||
adminLogBroadcastLimit = 200
|
||||
staleRoomCleanupInterval = 5 * time.Minute
|
||||
staleRoomTTL = 30 * time.Minute
|
||||
defaultMaxActivityLogEntries = 400
|
||||
defaultAdminLogBroadcastLimit = 200
|
||||
defaultStaleRoomCleanupInterval = 5 * time.Minute
|
||||
defaultStaleRoomTTL = 30 * time.Minute
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
mu sync.RWMutex
|
||||
rooms map[string]*Room
|
||||
store *DiskStore
|
||||
|
||||
maxActivityLogEntries int
|
||||
adminLogBroadcastLimit int
|
||||
staleRoomCleanupInterval time.Duration
|
||||
staleRoomTTL time.Duration
|
||||
}
|
||||
|
||||
func NewManager(dataPath string) (*Manager, error) {
|
||||
type ManagerOptions struct {
|
||||
MaxActivityLogEntries int
|
||||
AdminLogBroadcastLimit int
|
||||
StaleRoomCleanupInterval time.Duration
|
||||
StaleRoomTTL time.Duration
|
||||
}
|
||||
|
||||
func normalizeManagerOptions(opts ManagerOptions) ManagerOptions {
|
||||
if opts.MaxActivityLogEntries <= 0 {
|
||||
opts.MaxActivityLogEntries = defaultMaxActivityLogEntries
|
||||
}
|
||||
if opts.AdminLogBroadcastLimit <= 0 {
|
||||
opts.AdminLogBroadcastLimit = defaultAdminLogBroadcastLimit
|
||||
}
|
||||
if opts.StaleRoomCleanupInterval <= 0 {
|
||||
opts.StaleRoomCleanupInterval = defaultStaleRoomCleanupInterval
|
||||
}
|
||||
if opts.StaleRoomTTL <= 0 {
|
||||
opts.StaleRoomTTL = defaultStaleRoomTTL
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func NewManager(dataPath string, opts ManagerOptions) (*Manager, error) {
|
||||
store, err := NewDiskStore(dataPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
normalizedOpts := normalizeManagerOptions(opts)
|
||||
|
||||
manager := &Manager{
|
||||
rooms: make(map[string]*Room),
|
||||
store: store,
|
||||
maxActivityLogEntries: normalizedOpts.MaxActivityLogEntries,
|
||||
adminLogBroadcastLimit: normalizedOpts.AdminLogBroadcastLimit,
|
||||
staleRoomCleanupInterval: normalizedOpts.StaleRoomCleanupInterval,
|
||||
staleRoomTTL: normalizedOpts.StaleRoomTTL,
|
||||
}
|
||||
|
||||
if loadErr := manager.loadFromDisk(); loadErr != nil {
|
||||
@@ -43,7 +77,7 @@ func NewManager(dataPath string) (*Manager, error) {
|
||||
}
|
||||
|
||||
func (m *Manager) startCleanupLoop() {
|
||||
ticker := time.NewTicker(staleRoomCleanupInterval)
|
||||
ticker := time.NewTicker(m.staleRoomCleanupInterval)
|
||||
|
||||
go func() {
|
||||
defer ticker.Stop()
|
||||
@@ -65,7 +99,7 @@ func (m *Manager) cleanupStaleRooms(now time.Time) {
|
||||
room.mu.Lock()
|
||||
roomID := room.ID
|
||||
hasConnected := hasConnectedParticipantsLocked(room)
|
||||
recentlyActive := now.Sub(room.UpdatedAt) < staleRoomTTL
|
||||
recentlyActive := now.Sub(room.UpdatedAt) < m.staleRoomTTL
|
||||
hasSubscribers := len(room.subscribers) > 0
|
||||
room.mu.Unlock()
|
||||
|
||||
@@ -81,7 +115,7 @@ func (m *Manager) cleanupStaleRooms(now time.Time) {
|
||||
}
|
||||
|
||||
current.mu.Lock()
|
||||
if hasConnectedParticipantsLocked(current) || now.Sub(current.UpdatedAt) < staleRoomTTL || len(current.subscribers) > 0 {
|
||||
if hasConnectedParticipantsLocked(current) || now.Sub(current.UpdatedAt) < m.staleRoomTTL || len(current.subscribers) > 0 {
|
||||
current.mu.Unlock()
|
||||
m.mu.Unlock()
|
||||
continue
|
||||
@@ -747,8 +781,8 @@ func (m *Manager) marshalRoomState(room *Room, viewerParticipantID string) ([]by
|
||||
state.Links.AdminLink = "/room/" + room.ID + "?adminToken=" + room.AdminToken
|
||||
|
||||
start := 0
|
||||
if len(room.ActivityLog) > adminLogBroadcastLimit {
|
||||
start = len(room.ActivityLog) - adminLogBroadcastLimit
|
||||
if len(room.ActivityLog) > m.adminLogBroadcastLimit {
|
||||
start = len(room.ActivityLog) - m.adminLogBroadcastLimit
|
||||
}
|
||||
state.AdminLogs = make([]PublicActivityLogEntry, 0, len(room.ActivityLog)-start)
|
||||
for _, item := range room.ActivityLog[start:] {
|
||||
@@ -798,8 +832,8 @@ func (m *Manager) appendActivityLogLocked(room *Room, format string, args ...any
|
||||
Message: fmt.Sprintf(format, args...),
|
||||
})
|
||||
|
||||
if len(room.ActivityLog) > maxActivityLogEntries {
|
||||
room.ActivityLog = append([]ActivityLogEntry(nil), room.ActivityLog[len(room.ActivityLog)-maxActivityLogEntries:]...)
|
||||
if len(room.ActivityLog) > m.maxActivityLogEntries {
|
||||
room.ActivityLog = append([]ActivityLogEntry(nil), room.ActivityLog[len(room.ActivityLog)-m.maxActivityLogEntries:]...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user