- commit
- 92e3a32
- parent
- e1fca8b
- author
- Eric Bower
- date
- 2025-08-07 23:07:16 -0400 EDT
refactor(feeds): only fetch users with feeds post
4 files changed,
+40,
-1
+1,
-1
1@@ -586,7 +586,7 @@ func (f *Fetcher) SendEmail(logger *slog.Logger, username, email, subject string
2 }
3
4 func (f *Fetcher) Run(now time.Time) error {
5- users, err := f.db.FindUsers()
6+ users, err := f.db.FindUsersWithPost("feeds")
7 if err != nil {
8 return err
9 }
+1,
-0
1@@ -408,6 +408,7 @@ type DB interface {
2 FindPost(postID string) (*Post, error)
3 FindPostsForUser(pager *Pager, userID string, space string) (*Paginate[*Post], error)
4 FindAllPostsForUser(userID string, space string) ([]*Post, error)
5+ FindUsersWithPost(space string) ([]*User, error)
6 FindPostsBeforeDate(date *time.Time, space string) ([]*Post, error)
7 FindExpiredPosts(space string) ([]*Post, error)
8 FindUpdatedPostsForUser(userID string, space string) ([]*Post, error)
+34,
-0
1@@ -554,6 +554,40 @@ func (me *PsqlDB) FindPostsBeforeDate(date *time.Time, space string) ([]*db.Post
2 return posts, nil
3 }
4
5+func (me *PsqlDB) FindUsersWithPost(space string) ([]*db.User, error) {
6+ var users []*db.User
7+ rs, err := me.Db.Query(
8+ `SELECT u.id, u.name, u.created_at
9+ FROM app_users u
10+ INNER JOIN posts ON u.id=posts.user_id
11+ WHERE cur_space='feeds'
12+ GROUP BY u.id, u.name, u.created_at
13+ ORDER BY name ASC`,
14+ )
15+ if err != nil {
16+ return users, err
17+ }
18+ for rs.Next() {
19+ var name sql.NullString
20+ user := &db.User{}
21+ err := rs.Scan(
22+ &user.ID,
23+ &name,
24+ &user.CreatedAt,
25+ )
26+ if err != nil {
27+ return users, err
28+ }
29+ user.Name = name.String
30+
31+ users = append(users, user)
32+ }
33+ if rs.Err() != nil {
34+ return users, rs.Err()
35+ }
36+ return users, nil
37+}
38+
39 func (me *PsqlDB) FindUserForKey(username string, key string) (*db.User, error) {
40 me.Logger.Info("attempting to find user with only public key", "key", key)
41 pk, err := me.FindPublicKeyForKey(key)
+4,
-0
1@@ -284,3 +284,7 @@ func (me *StubDB) FindTunsEventLogs(userID string) ([]*db.TunsEventLog, error) {
2 func (me *StubDB) VisitUrlNotFound(opts *db.SummaryOpts) ([]*db.VisitUrl, error) {
3 return nil, errNotImpl
4 }
5+
6+func (me *StubDB) FindUsersWithPost(space string) ([]*db.User, error) {
7+ return nil, errNotImpl
8+}