Revert "internal/postgres: remove documentation delete"

This reverts commit 101343b2dd.

Reason for revert: We still need to delete rows when an "all" row is
inserted to prevent panics in https://go.googlesource.com/pkgsite/+/master/internal/build_context.go#51.

Change-Id: Ic2dec11978774cde4bffeba040ef2e212385e994
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/305949
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Julie Qiu 2021-03-30 17:38:40 +00:00
Родитель be5421da73
Коммит 5b4814e905
1 изменённых файлов: 14 добавлений и 1 удалений

Просмотреть файл

@ -510,7 +510,20 @@ func insertDocs(ctx context.Context, db *database.DB,
paths []string,
pathToUnitID map[string]int,
pathToDocs map[string][]*internal.Documentation) (err error) {
defer derrors.WrapStack(&err, "insertDocsCopy(%d paths)", len(paths))
defer derrors.WrapStack(&err, "insertDocs(%d paths)", len(paths))
// Remove old rows before inserting new ones, to get rid of obsolete rows.
// This is necessary because of the change to use all/all to represent documentation
// that is the same for all build contexts. It can be removed once all the DBs have
// been updated.
var unitIDs []int
for _, path := range paths {
unitIDs = append(unitIDs, pathToUnitID[path])
}
if _, err := db.Exec(ctx, `DELETE FROM documentation WHERE unit_id = ANY($1)`,
pq.Array(unitIDs)); err != nil {
return err
}
generateRows := func() chan database.RowItem {
ch := make(chan database.RowItem)