Refactor Store into SessionStore; move domain SQL onto User/Question/Answer.

This commit is contained in:
2026-08-22 02:40:51 -07:00
parent f31f352838
commit c77298411e
15 changed files with 696 additions and 876 deletions
+22 -7
View File
@@ -26,13 +26,28 @@ type sessionStopper interface {
StopCleanup()
}
// SessionStore returns the scs store backed by this database.
func (s *Store) SessionStore() scs.Store {
return s.sessionStore
// SessionStore wraps scs Postgres session persistence and cleanup.
type SessionStore struct {
store scs.Store
stopper sessionStopper
}
func (s *Store) initSessionStore(cleanupInterval time.Duration) {
ps := postgresstore.NewWithCleanupInterval(s.db, cleanupInterval)
s.sessionStore = ps
s.sessionStopper = ps
// NewSessionStore starts a postgresstore with the given cleanup interval.
func NewSessionStore(db *sql.DB, cleanupInterval time.Duration) *SessionStore {
ps := postgresstore.NewWithCleanupInterval(db, cleanupInterval)
return &SessionStore{store: ps, stopper: ps}
}
// Store returns the scs.Store implementation.
func (s *SessionStore) Store() scs.Store {
return s.store
}
// Close stops background session cleanup.
func (s *SessionStore) Close() {
if s == nil || s.stopper == nil {
return
}
s.stopper.StopCleanup()
s.stopper = nil
}