Skip to content

Commit

Permalink
fix: Keep bury-status between refresh-loops
Browse files Browse the repository at this point in the history
"delete PRs then insert the new batch" wasn't very friendly to existing
data. Most of it is ephemeral but the "buried" flag is actually a
feature of elly, so, let's keep that data.
  • Loading branch information
chelmertz committed Jun 20, 2024
1 parent 8fb1dcc commit 477eb2b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/storage/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ update prs set buried = true where url = ?;
-- name: Unbury :exec
update prs set buried = false where url = ?;

-- name: BuriedPrs :many
select url from prs where buried = true;

-- name: StoreLastFetched :exec
replace into meta (key, value) values ('last_fetched', ?);

Expand Down
27 changes: 27 additions & 0 deletions internal/storage/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ func (s *Storage) Prs() StoredState {
func (s *Storage) StoreRepoPrs(orderedPrs []types.ViewPr) error {
s.logger.Info("storing prs", slog.Int("prs", len(orderedPrs)))

buriedPrs, err := s.db.BuriedPrs(context.Background())
if err != nil {
s.logger.Error("could not fetch buried prs, throwing away old buried-status", slog.Any("err", err))
} else {
// O(n^2) but n is always small, in my case (and the amount of buried prs is usually super small)
for i, pr := range orderedPrs {
for _, buriedPr := range buriedPrs {
if buriedPr == pr.Url {
orderedPrs[i].Buried = true
break
}
}
}
}

if err := s.db.DeletePrs(context.Background()); err != nil {
return fmt.Errorf("could not delete old prs, in preparation of storing new ones: %w", err)
}
Expand All @@ -125,7 +140,7 @@ func (s *Storage) StoreRepoPrs(orderedPrs []types.ViewPr) error {
Additions: int64(pr.Additions),
Deletions: int64(pr.Deletions),
ReviewRequestedFromUsers: strings.Join(pr.ReviewRequestedFromUsers, ","),
Buried: false,
Buried: pr.Buried,
})
check(err)
}
Expand Down

0 comments on commit 477eb2b

Please sign in to comment.