Refactor Store into SessionStore; move domain SQL onto User/Question/Answer.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user