Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

1package indexer 2 3import ( 4 "context" 5 6 "github.com/bluesky-social/indigo/atproto/syntax" 7 "tangled.org/core/appview/db" 8 "tangled.org/core/appview/models" 9 "tangled.org/core/appview/notify" 10 "tangled.org/core/log" 11 "tangled.org/core/orm" 12) 13 14var _ notify.Notifier = &Indexer{} 15 16func (ix *Indexer) getAndReindexRepo(ctx context.Context, repoDid syntax.DID) { 17 l := log.FromContext(ctx).With("notifier", "indexer", "repo_did", repoDid) 18 19 repo, err := db.GetRepo(ix.Db, orm.FilterEq("repo_did", string(repoDid))) 20 if err != nil { 21 l.Error("failed to get repo for reindexing", "err", err) 22 return 23 } 24 25 err = ix.Repos.Index(ctx, *repo) 26 if err != nil { 27 l.Error("failed to reindex repo", "err", err) 28 } 29} 30 31func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) { 32 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 33 l.Debug("indexing new issue") 34 35 err := ix.Issues.Index(ctx, *issue) 36 if err != nil { 37 l.Error("failed to index an issue", "err", err) 38 } 39 40 l.Debug("reindexing repo after new issue") 41 ix.getAndReindexRepo(ctx, issue.RepoDid) 42} 43 44func (ix *Indexer) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 45 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 46 l.Debug("updating an issue") 47 err := ix.Issues.Index(ctx, *issue) 48 if err != nil { 49 l.Error("failed to index an issue", "err", err) 50 } 51} 52 53func (ix *Indexer) DeleteIssue(ctx context.Context, issue *models.Issue) { 54 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 55 l.Debug("deleting an issue") 56 57 err := ix.Issues.Delete(ctx, issue.Id) 58 if err != nil { 59 l.Error("failed to delete an issue", "err", err) 60 } 61 62 l.Debug("reindexing repo after issue deletion") 63 ix.getAndReindexRepo(ctx, issue.RepoDid) 64} 65 66func (ix *Indexer) NewIssueLabelOp(ctx context.Context, _ syntax.DID, issue *models.Issue, _ []models.LabelOp) { 67 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 68 l.Debug("reindexing issue after label change") 69 err := ix.Issues.Index(ctx, *issue) 70 if err != nil { 71 l.Error("failed to index an issue", "err", err) 72 } 73} 74 75func (ix *Indexer) NewPullLabelOp(ctx context.Context, _ syntax.DID, pull *models.Pull, _ []models.LabelOp) { 76 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 77 l.Debug("reindexing pull after label change") 78 err := ix.Pulls.Index(ctx, pull) 79 if err != nil { 80 l.Error("failed to index a pr", "err", err) 81 } 82} 83 84func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { 85 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 86 l.Debug("indexing new pr") 87 88 err := ix.Pulls.Index(ctx, pull) 89 if err != nil { 90 l.Error("failed to index a pr", "err", err) 91 } 92 93 l.Debug("reindexing repo after new pull") 94 ix.getAndReindexRepo(ctx, pull.RepoDid) 95} 96 97func (ix *Indexer) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 98 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 99 l.Debug("updating a pr") 100 err := ix.Pulls.Index(ctx, pull) 101 if err != nil { 102 l.Error("failed to index a pr", "err", err) 103 } 104} 105 106func (ix *Indexer) NewRepo(ctx context.Context, repo *models.Repo) { 107 l := log.FromContext(ctx).With("notifier", "indexer", "repo", repo.RepoIdentifier(), "owner", repo.Did, "name", repo.Name) 108 l.Debug("indexing new repo") 109 err := ix.Repos.Index(ctx, *repo) 110 if err != nil { 111 l.Error("failed to index a repo", "err", err) 112 } 113} 114 115func (ix *Indexer) RenameRepo(ctx context.Context, actor syntax.DID, oldRepo, newRepo *models.Repo) { 116 l := log.FromContext(ctx).With("notifier", "indexer", "repo", newRepo.RepoIdentifier(), "actor", actor, "old_name", oldRepo.Name, "new_name", newRepo.Name) 117 l.Debug("reindexing repo after rename") 118 err := ix.Repos.Index(ctx, *newRepo) 119 if err != nil { 120 l.Error("failed to reindex repo", "err", err) 121 } 122} 123 124func (ix *Indexer) DeleteRepo(ctx context.Context, repo *models.Repo) { 125 l := log.FromContext(ctx).With("notifier", "indexer", "repo", repo) 126 l.Debug("deleting repo from index") 127 err := ix.Repos.Delete(ctx, repo.Id) 128 if err != nil { 129 l.Error("failed to index a repo", "err", err) 130 } 131} 132 133func (ix *Indexer) NewStar(ctx context.Context, star *models.Star) { 134 l := log.FromContext(ctx).With("notifier", "indexer", "star", star) 135 136 if star.SubjectType != models.StarSubjectRepo { 137 return 138 } 139 140 l.Debug("reindexing repo after new star") 141 ix.getAndReindexRepo(ctx, syntax.DID(star.Subject)) 142} 143 144func (ix *Indexer) DeleteStar(ctx context.Context, star *models.Star) { 145 l := log.FromContext(ctx).With("notifier", "indexer", "star", star) 146 147 if star.SubjectType != models.StarSubjectRepo { 148 return 149 } 150 151 l.Debug("reindexing repo after star deletion") 152 ix.getAndReindexRepo(ctx, syntax.DID(star.Subject)) 153}