~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
5 4

[PATCH pages.sr.ht] Delete previous site version when publishing new one

Details
Message ID
<AfjbuyJNU6b3w0TxLtIAi64ZhAM9kBGdBRPrPYYNj7Y@cp3-web-051.plabs.ch>
DKIM signature
pass
Download raw message
Patch: +14 -0
---
 graph/schema.resolvers.go | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go
index 246f49627a3d..9739b07b9d86 100644
--- a/graph/schema.resolvers.go
+++ b/graph/schema.resolvers.go
@@ -158,6 +158,7 @@ func (r *mutationResolver) Publish(ctx context.Context, domain string, content g
		shasum := sha.Sum(nil)
		shahex := hex.EncodeToString(shasum[:])

		prevVersion := site.Version
		row = tx.QueryRowContext(ctx, `
			UPDATE sites SET version = $1 WHERE id = $2 RETURNING version;`,
			shahex, site.ID)
@@ -186,6 +187,19 @@ func (r *mutationResolver) Publish(ctx context.Context, domain string, content g
			}
		}

		if prevVersion != site.Version {
			prevS3path := path.Join(prefix, "sites", domain, prevVersion)
			och := mc.ListObjects(context.Background(), bucket, minio.ListObjectsOptions{
				Prefix:    prevS3path,
				Recursive: true,
			})

			for err := range mc.RemoveObjects(context.Background(),
				bucket, och, minio.RemoveObjectsOptions{}) {
				log.Printf("Failed to remove S3 object %q: %v", err.ObjectName, err.Err)
			}
		}

		return nil
	}); err != nil {
		cleanup()
-- 
2.33.0

[pages.sr.ht/patches] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CDTECDPBPF3L.DR2L9XIQUK8B@cirno2>
In-Reply-To
<AfjbuyJNU6b3w0TxLtIAi64ZhAM9kBGdBRPrPYYNj7Y@cp3-web-051.plabs.ch> (view parent)
DKIM signature
missing
Download raw message
pages.sr.ht/patches: FAILED in 1m19s

[Delete previous site version when publishing new one][0] from [Simon Ser][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/24684
[1]: contact@emersion.fr

✗ #574544 FAILED pages.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/574544
✗ #574545 FAILED pages.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/574545
Details
Message ID
<CDTFBS5686Z7.170JJVUZVDI5M@taiga>
In-Reply-To
<AfjbuyJNU6b3w0TxLtIAi64ZhAM9kBGdBRPrPYYNj7Y@cp3-web-051.plabs.ch> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
I wonder if for performance reasons we would be wise to shove this in a
cronjob instead, so we can return the response back to the user sooner.
Details
Message ID
<7wkCwX6mCfFYj4xL0PTagTQdNqMeHKLdXskfc4eV922YfYTl1HPtjQmC6v_XfnwWzlpyulMfKfXblYBUY41TQ7nKN8jPmIEOh3l_gqIPVJM=@emersion.fr>
In-Reply-To
<CDTFBS5686Z7.170JJVUZVDI5M@taiga> (view parent)
DKIM signature
pass
Download raw message
I'd say it's not worth it, the time taken to cleanup the previous
version should be insignificant compared to the time taken to upload
the new one in 99% of the cases. I'd go with the simple approach and
migrate to something more complicated if it really turns out to be an
issue in practice.
Details
Message ID
<58d28928-a2f7-4e32-a1ee-5848a2730f6c@www.fastmail.com>
In-Reply-To
<AfjbuyJNU6b3w0TxLtIAi64ZhAM9kBGdBRPrPYYNj7Y@cp3-web-051.plabs.ch> (view parent)
DKIM signature
missing
Download raw message
> I wonder if for performance reasons we would be wise to shove this in a
> cronjob instead, so we can return the response back to the user sooner.

Another possibility would be to clean the old files in a goroutine.

> +		if prevVersion != site.Version {

I think that the special version "pending" could be skipped as well:

> +		if prevVersion != site.Version && prevVersion != "pending" {
Details
Message ID
<CDWND0Z3D4TY.AAO5UO71O6DT@taiga>
In-Reply-To
<58d28928-a2f7-4e32-a1ee-5848a2730f6c@www.fastmail.com> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
On Sun Aug 29, 2021 at 4:30 PM CEST, Olivier C wrote:
> > I wonder if for performance reasons we would be wise to shove this in a
> > cronjob instead, so we can return the response back to the user sooner.
>
> Another possibility would be to clean the old files in a goroutine.

This seems liable to leave files behind if it fails or the server
crashes or whatnot.
Reply to thread Export thread (mbox)