diff --git a/appview/db/repos.go b/appview/db/repos.go --- a/appview/db/repos.go +++ b/appview/db/repos.go @@ -417,7 +417,7 @@ if repo.RepoDid != "" { repoDid = &repo.RepoDid } - _, err := tx.Exec( + result, err := tx.Exec( `insert into repos (did, name, knot, rkey, at_uri, description, website, topics, source, repo_did) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, @@ -426,6 +426,12 @@ if err != nil { return fmt.Errorf("failed to insert repo: %w", err) } + + id, err := result.LastInsertId() + if err != nil { + return fmt.Errorf("failed to get last insert id: %w", err) + } + repo.Id = id for _, dl := range repo.Labels { if err := SubscribeLabel(tx, &models.RepoLabel{ diff --git a/appview/indexer/notifier.go b/appview/indexer/notifier.go --- a/appview/indexer/notifier.go +++ b/appview/indexer/notifier.go @@ -105,9 +105,18 @@ } func (ix *Indexer) NewRepo(ctx context.Context, repo *models.Repo) { - l := log.FromContext(ctx).With("notifier", "indexer", "repo", repo) + l := log.FromContext(ctx).With("notifier", "indexer", "repo", repo.RepoIdentifier(), "owner", repo.Did, "name", repo.Name) l.Debug("indexing new repo") err := ix.Repos.Index(ctx, *repo) + if err != nil { + l.Error("failed to index a repo", "err", err) + } +} + +func (ix *Indexer) DeleteRepo(ctx context.Context, repo *models.Repo) { + l := log.FromContext(ctx).With("notifier", "indexer", "repo", repo) + l.Debug("deleting repo from index") + err := ix.Repos.Delete(ctx, repo.Id) if err != nil { l.Error("failed to index a repo", "err", err) } 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 @@ -34,6 +34,10 @@ m.fanout(func(n Notifier) { n.NewRepo(ctx, repo) }) } +func (m *mergedNotifier) DeleteRepo(ctx context.Context, repo *models.Repo) { + m.fanout(func(n Notifier) { n.DeleteRepo(ctx, repo) }) +} + func (m *mergedNotifier) NewStar(ctx context.Context, star *models.Star) { m.fanout(func(n Notifier) { n.NewStar(ctx, star) }) } diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -9,6 +9,7 @@ type Notifier interface { NewRepo(ctx context.Context, repo *models.Repo) + DeleteRepo(ctx context.Context, repo *models.Repo) NewStar(ctx context.Context, star *models.Star) DeleteStar(ctx context.Context, star *models.Star) @@ -44,7 +45,8 @@ var _ Notifier = &BaseNotifier{} -func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} +func (m *BaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) {} +func (m *BaseNotifier) DeleteRepo(ctx context.Context, repo *models.Repo) {} func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} diff --git a/appview/repo/repo.go b/appview/repo/repo.go --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -940,6 +940,7 @@ return } + rp.notifier.DeleteRepo(r.Context(), f) rp.pages.HxRedirect(w, fmt.Sprintf("/%s", f.Did)) } diff --git a/appview/state/search.go b/appview/state/search.go --- a/appview/state/search.go +++ b/appview/state/search.go @@ -47,8 +47,9 @@ var resultCount int var searchDuration time.Duration var docCount int64 + method := "bleve" - if searchOpts.HasSearchFilters() || sortField != "" { + if searchOpts.HasSearchFilters() || sortParam != "" { res, err := s.indexer.Repos.Search(r.Context(), searchOpts) if err != nil { l.Error("failed to search repos", "err", err) @@ -87,6 +88,7 @@ docCount = int64(dc) } else { + method = "db" repos, err = db.GetReposPaginated( s.db, page, @@ -109,6 +111,16 @@ resultCount = int(rc) docCount = int64(rc) } + + l.Info( + "RepoSearch", + "method", method, + "resultCount", resultCount, + "docCount", docCount, + "time", searchDuration, + "filterQuery", query.String(), + "sortParam", sortParam, + ) err = s.pages.SearchRepos(w, pages.SearchReposParams{ LoggedInUser: s.oauth.GetMultiAccountUser(r), diff --git a/appview/notify/db/db.go b/appview/notify/db/db.go --- a/appview/notify/db/db.go +++ b/appview/notify/db/db.go @@ -36,6 +36,9 @@ func (n *databaseNotifier) NewRepo(ctx context.Context, repo *models.Repo) { // no-op for now } +func (n *databaseNotifier) DeleteRepo(ctx context.Context, repo *models.Repo) { + // no-op for now +} func (n *databaseNotifier) NewStar(ctx context.Context, star *models.Star) { l := log.FromContext(ctx) diff --git a/appview/notify/logging/notifier.go b/appview/notify/logging/notifier.go --- a/appview/notify/logging/notifier.go +++ b/appview/notify/logging/notifier.go @@ -26,6 +26,11 @@ l.inner.NewRepo(ctx, repo) } +func (l *loggingNotifier) DeleteRepo(ctx context.Context, repo *models.Repo) { + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "DeleteRepo")) + l.inner.DeleteRepo(ctx, repo) +} + func (l *loggingNotifier) NewStar(ctx context.Context, star *models.Star) { ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewStar")) l.inner.NewStar(ctx, star)