Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assets:clean task is not cleaning predigested assets with .digest in the name #140

Open
tsrivishnu opened this issue May 29, 2023 · 7 comments

Comments

@tsrivishnu
Copy link

tsrivishnu commented May 29, 2023

Whenever rake assets:clean is run, the assets in public/assets with .digest in their name are not cleaned at all. This causes assets to accumulate on production and drastic increase in disk usage over time.

I realised that this is because of the following:

def extract_path_and_digest(digested_path)
digest = digested_path.to_s[/-([0-9a-f]{7,128})\.(?!digested)[^.]+\z/, 1]
path = digest ? digested_path.sub("-#{digest}", "") : digested_path
[path, digest]
end

The regex ignores all files that have a . digest in them.

Is this on purpose? or is this a bug?

@tsrivishnu tsrivishnu changed the title assets:clean task is not cleaning predigested assets with .digested in the name assets:clean task is not cleaning predigested assets with .digest in the name May 29, 2023
@tsrivishnu tsrivishnu changed the title assets:clean task is not cleaning predigested assets with .digest in the name assets:clean task is not cleaning predigested assets with .digest in the name May 29, 2023
@tsrivishnu
Copy link
Author

tsrivishnu commented May 29, 2023

Looks like there a brief mention of this in #110 but no (clear) resolution.

@brenogazzola
Copy link
Collaborator

It's a bug. Are you using esbuild and allowing chunking?

@tsrivishnu
Copy link
Author

tsrivishnu commented May 29, 2023 via email

@brenogazzola
Copy link
Collaborator

I think the problem is caused by #100 which I'm considering reverting as it's causing multiple problems, I just need confirmation. Last question: Do all chunks have the same base name and only differ in the digest?

I'm asking because clean is actually working for me, keeping only the 3 most recent versions of each file

@brenogazzola
Copy link
Collaborator

Actually, I just figured it out. Clean is not going to work because each file name is unique due to the digest, and therefore Propshaft cannot group them into "versions" to delete the old ones.

I'll have to think a bit about how to handle this (I would also welcome a PR)

@tsrivishnu
Copy link
Author

Examples of pre-digested files:

public/assets/Vue3Lottie-1ea0f3b6ddc59bef7019.digested.js
public/assets/Vue3Lottie-23af1d5aa7baee8b1ca8.digested.js
public/assets/Vue3Lottie-26a7aeceee4e261a29b5.digested.js
public/assets/Vue3Lottie-337a4df42c71a547bccd.digested.js
public/assets/Vue3Lottie-3d0d69a396646d61f938.digested.js
public/assets/Vue3Lottie-41282d7f6fa2d6b4d891.digested.js

public/assets/Vue3Lottie-1ea0f3b6ddc59bef7019.digested.js-261e2968c4f774cb50ba.digested.map
public/assets/Vue3Lottie-23af1d5aa7baee8b1ca8.digested.js-c3e14423760666ecd16d.digested.map
public/assets/Vue3Lottie-26a7aeceee4e261a29b5.digested.js-c9d39559c1296b3e0dab.digested.map
public/assets/Vue3Lottie-337a4df42c71a547bccd.digested.js-27763e2e7bdcf11da3ff.digested.map
public/assets/Vue3Lottie-3d0d69a396646d61f938.digested.js-32f969d5062f50ff3a60.digested.map
public/assets/Vue3Lottie-41282d7f6fa2d6b4d891.digested.js-abed1ffa6c0eaad60d5a.digested.map

public/assets/Vue3Lottie-1ea0f3b6ddc59bef7019.digested.js.LICENSE.txt
public/assets/Vue3Lottie-23af1d5aa7baee8b1ca8.digested.js.LICENSE.txt
public/assets/Vue3Lottie-26a7aeceee4e261a29b5.digested.js.LICENSE.txt
public/assets/Vue3Lottie-337a4df42c71a547bccd.digested.js.LICENSE.txt
public/assets/Vue3Lottie-3d0d69a396646d61f938.digested.js.LICENSE.txt
public/assets/Vue3Lottie-41282d7f6fa2d6b4d891.digested.js.LICENSE.txt

I can look into it sometime to see if I can make a PR. At least, I will try to give a workaround script using the manifest to clear unused assets.

@brenogazzola
Copy link
Collaborator

I'd love to say we could just group them by the name before the digest, but esbuild gives all chunks the same name and that would break it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants