Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

appview: re-index issues and pulls when labels are modified

Signed-off-by: Thomas Karpiniec <tkarpiniec@icloud.com>

authored by octet-stream.net and committed by tangled.org b162fea0 79d5bed4

+64
+18
appview/indexer/notifier.go
··· 38 38 } 39 39 } 40 40 41 + func (ix *Indexer) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 42 + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 43 + l.Debug("reindexing issue after label change") 44 + err := ix.Issues.Index(ctx, *issue) 45 + if err != nil { 46 + l.Error("failed to index an issue", "err", err) 47 + } 48 + } 49 + 50 + func (ix *Indexer) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 51 + l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 52 + l.Debug("reindexing pull after label change") 53 + err := ix.Pulls.Index(ctx, pull) 54 + if err != nil { 55 + l.Error("failed to index a pr", "err", err) 56 + } 57 + } 58 + 41 59 func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { 42 60 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 43 61 l.Debug("indexing new pr")
+18
appview/labels/labels.go
··· 13 13 "tangled.org/core/appview/db" 14 14 "tangled.org/core/appview/middleware" 15 15 "tangled.org/core/appview/models" 16 + "tangled.org/core/appview/notify" 16 17 "tangled.org/core/appview/oauth" 17 18 "tangled.org/core/appview/pages" 18 19 "tangled.org/core/appview/validator" ··· 35 34 logger *slog.Logger 36 35 validator *validator.Validator 37 36 enforcer *rbac.Enforcer 37 + notifier notify.Notifier 38 38 } 39 39 40 40 func New( ··· 44 42 db *db.DB, 45 43 validator *validator.Validator, 46 44 enforcer *rbac.Enforcer, 45 + notifier notify.Notifier, 47 46 logger *slog.Logger, 48 47 ) *Labels { 49 48 return &Labels{ ··· 54 51 logger: logger, 55 52 validator: validator, 56 53 enforcer: enforcer, 54 + notifier: notifier, 57 55 } 58 56 } 59 57 ··· 248 244 249 245 // clear aturi when everything is successful 250 246 atUri = "" 247 + 248 + subject := syntax.ATURI(subjectUri) 249 + if subject.Collection() == tangled.RepoIssueNSID { 250 + issues, err := db.GetIssues(l.db, orm.FilterEq("at_uri", subjectUri)) 251 + if err == nil && len(issues) == 1 { 252 + l.notifier.NewIssueLabelOp(r.Context(), &issues[0]) 253 + } 254 + } 255 + if subject.Collection() == tangled.RepoPullNSID { 256 + pulls, err := db.GetPulls(l.db, orm.FilterEq("at_uri", subjectUri)) 257 + if err == nil && len(pulls) == 1 { 258 + l.notifier.NewPullLabelOp(r.Context(), pulls[0]) 259 + } 260 + } 251 261 252 262 l.pages.HxRefresh(w) 253 263 }
+3
appview/notify/db/db.go
··· 206 206 // no-op for now 207 207 } 208 208 209 + func (n *databaseNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) {} 210 + func (n *databaseNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) {} 211 + 209 212 func (n *databaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 210 213 actorDid := syntax.DID(follow.UserDid) 211 214 recipients := sets.Singleton(syntax.DID(follow.SubjectDid))
+10
appview/notify/logging_notifier.go
··· 59 59 l.inner.DeleteIssue(ctx, issue) 60 60 } 61 61 62 + func (l *loggingNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 63 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewIssueLabelOp")) 64 + l.inner.NewIssueLabelOp(ctx, issue) 65 + } 66 + 67 + func (l *loggingNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 68 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewPullLabelOp")) 69 + l.inner.NewPullLabelOp(ctx, pull) 70 + } 71 + 62 72 func (l *loggingNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 63 73 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewFollow")) 64 74 l.inner.NewFollow(ctx, follow)
+8
appview/notify/merged_notifier.go
··· 58 58 m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) 59 59 } 60 60 61 + func (m *mergedNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 62 + m.fanout(func(n Notifier) { n.NewIssueLabelOp(ctx, issue) }) 63 + } 64 + 65 + func (m *mergedNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 66 + m.fanout(func(n Notifier) { n.NewPullLabelOp(ctx, pull) }) 67 + } 68 + 61 69 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 62 70 m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) 63 71 }
+6
appview/notify/notifier.go
··· 25 25 NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 27 28 + NewIssueLabelOp(ctx context.Context, issue *models.Issue) 29 + NewPullLabelOp(ctx context.Context, pull *models.Pull) 30 + 28 31 UpdateProfile(ctx context.Context, profile *models.Profile) 29 32 30 33 NewString(ctx context.Context, s *models.String) ··· 52 49 } 53 50 func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 54 51 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 52 + 53 + func (m *BaseNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) {} 54 + func (m *BaseNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) {} 55 55 56 56 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 57 57 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
+1
appview/state/router.go
··· 340 340 s.db, 341 341 s.validator, 342 342 s.enforcer, 343 + s.notifier, 343 344 log.SubLogger(s.logger, "labels"), 344 345 ) 345 346 return ls.Router()