From c07ba238ee5b1bc40ec9ce94ced63a4490255cc2 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 23 Sep 2025 10:32:48 +0000 Subject: [PATCH] appview/models: move db.Star into models Signed-off-by: oppiliappan --- appview/ingester.go | 2 +- appview/db/star.go | 44 ++++++++++---------------------------------- appview/db/timeline.go | 2 +- appview/models/star.go | 17 +++++++++++++++++ appview/notify/merged_notifier.go | 4 ++-- appview/notify/notifier.go | 8 ++++---- appview/posthog/notifier.go | 4 ++-- appview/state/star.go | 2 +- 8 file(s) changed, 38 insertion(s)(+), 45 deletion(s)(-) diff --git a/appview/ingester.go b/appview/ingester.go --- a/appview/ingester.go +++ b/appview/ingester.go @@ -116,7 +116,7 @@ l.Error("invalid record", "err", err) return err } - err = db.AddStar(i.Db, &db.Star{ + err = db.AddStar(i.Db, &models.Star{ StarredByDid: did, RepoAt: subjectUri, Rkey: e.Commit.RKey, diff --git a/appview/db/star.go b/appview/db/star.go --- a/appview/db/star.go +++ b/appview/db/star.go @@ -12,31 +12,7 @@ "tangled.org/core/appview/models" ) -type Star struct { - StarredByDid string - RepoAt syntax.ATURI - Created time.Time - Rkey string - - // optionally, populate this when querying for reverse mappings - Repo *models.Repo -} - -func (star *Star) ResolveRepo(e Execer) error { - if star.Repo != nil { - return nil - } - - repo, err := GetRepoByAtUri(e, star.RepoAt.String()) - if err != nil { - return err - } - - star.Repo = repo - return nil -} - -func AddStar(e Execer, star *Star) error { +func AddStar(e Execer, star *models.Star) error { query := `insert or ignore into stars (starred_by_did, repo_at, rkey) values (?, ?, ?)` _, err := e.Exec( query, @@ -48,14 +24,14 @@ } // Get a star record -func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*Star, error) { +func GetStar(e Execer, starredByDid string, repoAt syntax.ATURI) (*models.Star, error) { query := ` select starred_by_did, repo_at, created, rkey from stars where starred_by_did = ? and repo_at = ?` row := e.QueryRow(query, starredByDid, repoAt) - var star Star + var star models.Star var created string err := row.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) if err != nil { @@ -153,7 +129,7 @@ func GetStarStatuses(e Execer, userDid string, repoAts []syntax.ATURI) (map[string]bool, error) { return getStarStatuses(e, userDid, repoAts) } -func GetStars(e Execer, limit int, filters ...filter) ([]Star, error) { +func GetStars(e Execer, limit int, filters ...filter) ([]models.Star, error) { var conditions []string var args []any for _, filter := range filters { @@ -185,9 +161,9 @@ return nil, err } - starMap := make(map[string][]Star) + starMap := make(map[string][]models.Star) for rows.Next() { - var star Star + var star models.Star var created string err := rows.Scan(&star.StarredByDid, &star.RepoAt, &created, &star.Rkey) if err != nil { @@ -228,7 +204,7 @@ } } - var stars []Star + var stars []models.Star for _, s := range starMap { stars = append(stars, s...) } @@ -260,8 +236,8 @@ return count, nil } -func GetAllStars(e Execer, limit int) ([]Star, error) { - var stars []Star +func GetAllStars(e Execer, limit int) ([]models.Star, error) { + var stars []models.Star rows, err := e.Query(` select @@ -284,7 +260,7 @@ defer rows.Close() for rows.Next() { - var star Star + var star models.Star var repo models.Repo var starCreatedAt, repoCreatedAt string diff --git a/appview/db/timeline.go b/appview/db/timeline.go --- a/appview/db/timeline.go +++ b/appview/db/timeline.go @@ -11,7 +11,7 @@ type TimelineEvent struct { *models.Repo *models.Follow - *Star + *models.Star EventAt time.Time diff --git a/appview/models/star.go b/appview/models/star.go new file mode 100644 --- /dev/null +++ b/appview/models/star.go @@ -0,0 +1,17 @@ +package models + +import ( + "time" + + "github.com/bluesky-social/indigo/atproto/syntax" +) + +type Star struct { + StarredByDid string + RepoAt syntax.ATURI + Created time.Time + Rkey string + + // optionally, populate this when querying for reverse mappings + Repo *Repo +} diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -23,12 +23,12 @@ } } -func (m *mergedNotifier) NewStar(ctx context.Context, star *db.Star) { +func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { for _, notifier := range m.notifiers { notifier.NewStar(ctx, star) } } -func (m *mergedNotifier) DeleteStar(ctx context.Context, star *db.Star) { +func (m *mergedNotifier) DeleteStar(ctx context.Context, star *models.Star) { for _, notifier := range m.notifiers { notifier.DeleteStar(ctx, star) } diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -10,8 +10,8 @@ type Notifier interface { NewRepo(ctx context.Context, repo *models.Repo) - NewStar(ctx context.Context, star *db.Star) - DeleteStar(ctx context.Context, star *db.Star) + NewStar(ctx context.Context, star *models.Star) + DeleteStar(ctx context.Context, star *models.Star) NewIssue(ctx context.Context, issue *models.Issue) @@ -35,8 +35,8 @@ func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} -func (m *BaseNotifier) NewStar(ctx context.Context, star *db.Star) {} -func (m *BaseNotifier) DeleteStar(ctx context.Context, star *db.Star) {} +func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} +func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} diff --git a/appview/posthog/notifier.go b/appview/posthog/notifier.go --- a/appview/posthog/notifier.go +++ b/appview/posthog/notifier.go @@ -35,7 +35,7 @@ } } -func (n *posthogNotifier) NewStar(ctx context.Context, star *db.Star) { +func (n *posthogNotifier) NewStar(ctx context.Context, star *models.Star) { err := n.client.Enqueue(posthog.Capture{ DistinctId: star.StarredByDid, Event: "star", @@ -46,7 +46,7 @@ } } -func (n *posthogNotifier) DeleteStar(ctx context.Context, star *db.Star) { +func (n *posthogNotifier) DeleteStar(ctx context.Context, star *models.Star) { err := n.client.Enqueue(posthog.Capture{ DistinctId: star.StarredByDid, Event: "unstar", diff --git a/appview/state/star.go b/appview/state/star.go --- a/appview/state/star.go +++ b/appview/state/star.go @@ -56,7 +56,7 @@ } log.Println("created atproto record: ", resp.Uri) - star := &db.Star{ + star := &models.Star{ StarredByDid: currentUser.Did, RepoAt: subjectUri, Rkey: rkey, -- tangled.sh