Skip to content

Commit b149388

Browse files
committed
split lfs size from repository size
releated to #21820 splite `Size` in repository table as two colunms, one is `Size` for git size, the other is `LFSSize` for lfs data. still show full size on ui, but show each of them by a `title`; still response full size in api response. Signed-off-by: a1012112796 <[email protected]>
1 parent 7b5b739 commit b149388

File tree

10 files changed

+42
-9
lines changed

10 files changed

+42
-9
lines changed

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ var migrations = []Migration{
457457
NewMigration("Add actions tables", v1_19.AddActionsTables),
458458
// v241 -> v242
459459
NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable),
460+
// v242 -> v243
461+
NewMigration("Add lfs_size column to repository table", v1_19.AddLFSSizeToRepositoryTable),
460462
}
461463

462464
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v242.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_19 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
// AddLFSSizeToRepositoryTable: add LFSSize column to Repository
11+
func AddLFSSizeToRepositoryTable(x *xorm.Engine) error {
12+
type Repository struct {
13+
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
14+
}
15+
16+
return x.Sync2(new(Repository))
17+
}

models/repo/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type Repository struct {
163163
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
164164
TemplateID int64 `xorm:"INDEX"`
165165
Size int64 `xorm:"NOT NULL DEFAULT 0"`
166+
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
166167
CodeIndexerStatus *RepoIndexerStatus `xorm:"-"`
167168
StatsIndexerStatus *RepoIndexerStatus `xorm:"-"`
168169
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`

models/repo/update.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
185185
}
186186

187187
// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
188-
func UpdateRepoSize(ctx context.Context, repoID, size int64) error {
189-
_, err := db.GetEngine(ctx).ID(repoID).Cols("size").NoAutoTime().Update(&Repository{
190-
Size: size,
188+
func UpdateRepoSize(ctx context.Context, repoID, size, lfsSize int64) error {
189+
_, err := db.GetEngine(ctx).ID(repoID).Cols("size", "lfs_size").NoAutoTime().Update(&Repository{
190+
Size: size,
191+
LFSSize: lfsSize,
191192
})
192193
return err
193194
}

modules/repository/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error {
330330
return fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err)
331331
}
332332

333-
return repo_model.UpdateRepoSize(ctx, repo.ID, size+lfsSize)
333+
return repo_model.UpdateRepoSize(ctx, repo.ID, size, lfsSize)
334334
}
335335

336336
// CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon...

modules/templates/helper.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ func NewFuncMap() []template.FuncMap {
127127
}
128128
return sum
129129
},
130+
"Add64": func(a ...int64) int64 {
131+
sum := int64(0)
132+
for _, val := range a {
133+
sum += val
134+
}
135+
return sum
136+
},
130137
"Mul": func(a ...int) int {
131138
sum := 1
132139
for _, val := range a {

services/convert/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc
148148
Template: repo.IsTemplate,
149149
Empty: repo.IsEmpty,
150150
Archived: repo.IsArchived,
151-
Size: int(repo.Size / 1024),
151+
Size: int((repo.Size + repo.LFSSize) / 1024),
152152
Fork: repo.IsFork,
153153
Parent: parent,
154154
Mirror: repo.IsMirror,

templates/repo/settings/options.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
1717
<input id="repo_name" name="repo_name" value="{{.Repository.Name}}" data-repo-name="{{.Repository.Name}}" autofocus required>
1818
</div>
19-
<div class="inline field">
19+
<div class="inline field" title="git: {{FileSize .Repository.Size }}, lfs: {{FileSize .Repository.LFSSize}}">
2020
<label>{{.locale.Tr "repo.repo_size"}}</label>
21-
<span>{{FileSize .Repository.Size}}</span>
21+
<span>{{FileSize (Add64 .Repository.Size .Repository.LFSSize)}}</span>
2222
</div>
2323
<div class="inline field">
2424
<label>{{.locale.Tr "repo.template"}}</label>

templates/repo/sub_menu.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
</div>
1616
{{end}}
1717
<div class="item">
18-
<span class="ui">{{svg "octicon-database"}} <b>{{FileSize .Repository.Size}}</b></span>
18+
<span class="ui" title="git: {{FileSize .Repository.Size }}, lfs: {{FileSize .Repository.LFSSize}}">
19+
{{svg "octicon-database"}}
20+
<b>{{FileSize (Add64 .Repository.Size .Repository.LFSSize)}}</b>
21+
</span>
1922
</div>
2023
{{end}}
2124
</div>

templates/user/settings/repos.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
<span class="icon">{{svg "octicon-repo"}}</span>
2828
{{end}}
2929
<a class="name" href="{{$repo.Link}}">{{$repo.OwnerName}}/{{$repo.Name}}</a>
30-
<span>{{FileSize $repo.Size}}</span>
30+
<span title="git: {{FileSize $repo.Size }}, lfs: {{FileSize $repo.LFSSize}}">
31+
{{FileSize (Add64 $repo.Size $repo.LFSSize)}}
32+
</span>
3133
{{if $repo.IsFork}}
3234
{{$.locale.Tr "repo.forked_from"}}
3335
<span><a href="{{$repo.BaseRepo.Link}}">{{$repo.BaseRepo.OwnerName}}/{{$repo.BaseRepo.Name}}</a></span>

0 commit comments

Comments
 (0)