just overwrite bundles, don't delete then re-add

This commit is contained in:
Joe Lothan 2026-05-20 00:09:53 -04:00
parent d6ef34a1dc
commit eb40995c60
3 changed files with 2 additions and 56 deletions

View file

@ -72,10 +72,3 @@ func isSVG(data []byte) bool {
header := data[:min(256, len(data))]
return bytes.Contains(header, []byte("<svg")) || bytes.Contains(header, []byte("<?xml"))
}
func min(a, b int) int {
if a < b {
return a
}
return b
}

View file

@ -107,15 +107,9 @@ func main() {
os.MkdirAll(cfg.OutputDir, 0755)
}
// Clean old bundles before writing new ones
if !cfg.DryRun {
fmt.Println("Cleaning old bundles from S3...")
if err := s3DeletePrefix(cfg.SiteBucket, "tabs/"); err != nil {
log.Fatalf("Failed to clean old bundles: %v", err)
}
}
// Stream hosts from DB in pages, convert icons, write bundles incrementally
// Bundles are written in-place (overwriting previous run). No delete-first step,
// so the live site always has valid data even if bundle gen crashes midway.
fmt.Println("Processing hosts and writing bundles...")
bundleCount := 0
@ -240,10 +234,3 @@ func main() {
writeStats(stats)
}
func max(a, b int) int {
if a > b {
return a
}
return b
}

View file

@ -3,14 +3,12 @@ package main
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
)
var s3Client *s3.Client
@ -48,35 +46,3 @@ func s3UploadBundle(bucket, key string, data []byte) error {
return err
}
// s3DeletePrefix deletes all objects under a prefix in S3.
func s3DeletePrefix(bucket, prefix string) error {
ctx := context.Background()
paginator := s3.NewListObjectsV2Paginator(s3Client, &s3.ListObjectsV2Input{
Bucket: aws.String(bucket),
Prefix: aws.String(prefix),
})
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
return err
}
if len(page.Contents) == 0 {
continue
}
var objects []types.ObjectIdentifier
for _, obj := range page.Contents {
objects = append(objects, types.ObjectIdentifier{Key: obj.Key})
}
_, err = s3Client.DeleteObjects(ctx, &s3.DeleteObjectsInput{
Bucket: aws.String(bucket),
Delete: &types.Delete{Objects: objects},
})
if err != nil {
return fmt.Errorf("delete batch: %w", err)
}
}
return nil
}