mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	[v11.0/forgejo] fix: ignore expired artifacts for quota calculation (#7985)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/7976 - Expired artifacts are kept in the database but the artifact has been deleted from the storage. Ignore them for the quota calculation. - Added unit test. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7985 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
		
					parent
					
						
							
								e9f0e96a27
							
						
					
				
			
			
				commit
				
					
						ed87ecd17f
					
				
			
		
					 4 changed files with 61 additions and 1 deletions
				
			
		
							
								
								
									
										17
									
								
								models/fixtures/TestGetUsedForUser/action_artifact.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								models/fixtures/TestGetUsedForUser/action_artifact.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
-
 | 
			
		||||
  id: 1001
 | 
			
		||||
  run_id: 792
 | 
			
		||||
  runner_id: 1
 | 
			
		||||
  repo_id: 4
 | 
			
		||||
  owner_id: 1
 | 
			
		||||
  commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
 | 
			
		||||
  storage_path: "27/5/1730330775594233150.chunk"
 | 
			
		||||
  file_size: 693147180559
 | 
			
		||||
  file_compressed_size: 693147180559
 | 
			
		||||
  content_encoding: "application/zip"
 | 
			
		||||
  artifact_path: "big-file.zip"
 | 
			
		||||
  artifact_name: "big-file"
 | 
			
		||||
  status: 4
 | 
			
		||||
  created_unix: 1730330775
 | 
			
		||||
  updated_unix: 1730330775
 | 
			
		||||
  expired_unix: 1738106775
 | 
			
		||||
							
								
								
									
										19
									
								
								models/quota/main_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								models/quota/main_test.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
 | 
			
		||||
// SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
package quota
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"forgejo.org/models/unittest"
 | 
			
		||||
 | 
			
		||||
	_ "forgejo.org/models"
 | 
			
		||||
	_ "forgejo.org/models/actions"
 | 
			
		||||
	_ "forgejo.org/models/activities"
 | 
			
		||||
	_ "forgejo.org/models/forgefed"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestMain(m *testing.M) {
 | 
			
		||||
	unittest.MainTest(m)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -131,7 +131,8 @@ func createQueryFor(ctx context.Context, userID int64, q string) db.Engine {
 | 
			
		|||
	case "artifacts":
 | 
			
		||||
		session = session.
 | 
			
		||||
			Table("action_artifact").
 | 
			
		||||
			Join("INNER", "`repository`", "`action_artifact`.repo_id = `repository`.id")
 | 
			
		||||
			Join("INNER", "`repository`", "`action_artifact`.repo_id = `repository`.id").
 | 
			
		||||
			Where("`action_artifact`.status != ?", action_model.ArtifactStatusExpired)
 | 
			
		||||
	case "packages":
 | 
			
		||||
		session = session.
 | 
			
		||||
			Table("package_version").
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										23
									
								
								models/quota/used_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								models/quota/used_test.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
 | 
			
		||||
// SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
package quota
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"forgejo.org/models/unittest"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
	"github.com/stretchr/testify/require"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestGetUsedForUser(t *testing.T) {
 | 
			
		||||
	defer unittest.OverrideFixtures("models/fixtures/TestGetUsedForUser/")()
 | 
			
		||||
	require.NoError(t, unittest.PrepareTestDatabase())
 | 
			
		||||
 | 
			
		||||
	used, err := GetUsedForUser(t.Context(), 5)
 | 
			
		||||
	require.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
	assert.EqualValues(t, 4096, used.Size.Assets.Artifacts)
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue