Phase 13, part 1: a Postgres schema per team
On the multi-tenant edition each team's data is in its own schema; the tables every team shares (people, sessions, memberships, keys, locks, and a new teams table) stay in the main one. A team's connection pool searches its own schema first, so the app's SQL runs unchanged and can't reach another team's tables. Each request is served by a copy of the Server for the viewer's team, with that team's database, secrets and caches; agents work on their own team's. The local and server editions are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-15
@@ -137,19 +137,20 @@ func (s *Server) redditReader(ctx context.Context) (*reddit.Client, error) {
|
||||
if id == "" || secret == "" {
|
||||
return nil, errors.New("add Reddit's client ID and secret under Settings → Social accounts to read subreddits")
|
||||
}
|
||||
s.mu.Lock()
|
||||
tok, exp := s.redditAppToken, s.redditAppTokenExp
|
||||
s.mu.Unlock()
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
tok, exp := tc.redditAppToken, tc.redditAppTokenExp
|
||||
tc.mu.Unlock()
|
||||
if tok == "" || time.Now().After(exp) {
|
||||
res, err := oauth.RedditAppToken(ctx, id, secret, s.redditUserAgent())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tok = res.AccessToken
|
||||
s.mu.Lock()
|
||||
tc.mu.Lock()
|
||||
// Reddit's app tokens last an hour; renew a little early.
|
||||
s.redditAppToken, s.redditAppTokenExp = tok, time.Now().Add(50*time.Minute)
|
||||
s.mu.Unlock()
|
||||
tc.redditAppToken, tc.redditAppTokenExp = tok, time.Now().Add(50*time.Minute)
|
||||
tc.mu.Unlock()
|
||||
}
|
||||
return reddit.New(tok, s.redditUserAgent(), nil), nil
|
||||
}
|
||||
@@ -193,9 +194,10 @@ func (s *Server) redditHistory(ctx context.Context) []reddit.Submission {
|
||||
return nil
|
||||
}
|
||||
user, c := a.External, s.redditClient(a)
|
||||
s.mu.Lock()
|
||||
h, at := s.redditHist, s.redditHistAt
|
||||
s.mu.Unlock()
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
h, at := tc.redditHist, tc.redditHistAt
|
||||
tc.mu.Unlock()
|
||||
if h != nil && time.Since(at) < redditHistoryTTL {
|
||||
return h
|
||||
}
|
||||
@@ -207,15 +209,16 @@ func (s *Server) redditHistory(ctx context.Context) []reddit.Submission {
|
||||
if h == nil {
|
||||
h = []reddit.Submission{}
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.redditHist, s.redditHistAt = h, time.Now()
|
||||
s.mu.Unlock()
|
||||
tc.mu.Lock()
|
||||
tc.redditHist, tc.redditHistAt = h, time.Now()
|
||||
tc.mu.Unlock()
|
||||
return h
|
||||
}
|
||||
|
||||
// forgetRedditHistory drops the cached posts after posting.
|
||||
func (s *Server) forgetRedditHistory() {
|
||||
s.mu.Lock()
|
||||
s.redditHist = nil
|
||||
s.mu.Unlock()
|
||||
tc := s.cache()
|
||||
tc.mu.Lock()
|
||||
tc.redditHist = nil
|
||||
tc.mu.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user