Skip to content

Commit 0c047b3

Browse files
committed
use repo size detail
Signed-off-by: a1012112796 <[email protected]>
1 parent ede9146 commit 0c047b3

File tree

8 files changed

+41
-21
lines changed

8 files changed

+41
-21
lines changed

models/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ var migrations = []Migration{
460460
// v242 -> v243
461461
NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText),
462462
// v243 -> v244
463-
NewMigration("Add lfs_size column to repository table", v1_19.AddLFSSizeToRepositoryTable),
463+
NewMigration("Add size_details column to repository table", v1_19.AddSizeDetailsToRepositoryTable),
464464
}
465465

466466
// GetCurrentDBVersion returns the current db version

models/migrations/v1_19/v243.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import (
77
"xorm.io/xorm"
88
)
99

10-
// AddLFSSizeToRepositoryTable: add LFSSize column to Repository
11-
func AddLFSSizeToRepositoryTable(x *xorm.Engine) error {
10+
type SizeDetails struct {
11+
GitSize int64
12+
LFSSize int64
13+
// TODO: size of more parts.
14+
}
15+
16+
// AddSizeDetailsToRepositoryTable: add LFSSize column to Repository
17+
func AddSizeDetailsToRepositoryTable(x *xorm.Engine) error {
1218
type Repository struct {
13-
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
19+
SizeDetails SizeDetails `xorm:"TEXT JSON"`
1420
}
1521

1622
return x.Sync2(new(Repository))

models/repo/repo.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"code.gitea.io/gitea/models/db"
1717
"code.gitea.io/gitea/models/unit"
1818
user_model "code.gitea.io/gitea/models/user"
19+
"code.gitea.io/gitea/modules/base"
1920
"code.gitea.io/gitea/modules/log"
2021
"code.gitea.io/gitea/modules/markup"
2122
"code.gitea.io/gitea/modules/setting"
@@ -112,6 +113,17 @@ const (
112113
RepositoryBroken // repository is in a permanently broken state
113114
)
114115

116+
// SizeDetails represents size of each part for a Repository
117+
type SizeDetails struct {
118+
GitSize int64
119+
LFSSize int64
120+
// TODO: size of more parts.
121+
}
122+
123+
func (s SizeDetails) String() string {
124+
return fmt.Sprintf("git: " + base.FileSize(s.GitSize) + ", lfs: " + base.FileSize(s.LFSSize))
125+
}
126+
115127
// Repository represents a git repository.
116128
type Repository struct {
117129
ID int64 `xorm:"pk autoincr"`
@@ -157,14 +169,13 @@ type Repository struct {
157169
Units []*RepoUnit `xorm:"-"`
158170
PrimaryLanguage *LanguageStat `xorm:"-"`
159171

160-
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
161-
ForkID int64 `xorm:"INDEX"`
162-
BaseRepo *Repository `xorm:"-"`
163-
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
164-
TemplateID int64 `xorm:"INDEX"`
165-
// the size of git repository directory itself, not include lfs/package/attachment size
172+
IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"`
173+
ForkID int64 `xorm:"INDEX"`
174+
BaseRepo *Repository `xorm:"-"`
175+
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
176+
TemplateID int64 `xorm:"INDEX"`
166177
Size int64 `xorm:"NOT NULL DEFAULT 0"`
167-
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
178+
SizeDetails SizeDetails `xorm:"TEXT JSON"`
168179
CodeIndexerStatus *RepoIndexerStatus `xorm:"-"`
169180
StatsIndexerStatus *RepoIndexerStatus `xorm:"-"`
170181
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`

models/repo/update.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,12 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
186186

187187
// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
188188
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,
189+
_, err := db.GetEngine(ctx).ID(repoID).Cols("size", "size_details").NoAutoTime().Update(&Repository{
190+
Size: size + lfsSize,
191+
SizeDetails: SizeDetails{
192+
GitSize: size,
193+
LFSSize: lfsSize,
194+
},
192195
})
193196
return err
194197
}

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 + repo.LFSSize) / 1024),
151+
Size: int(repo.Size / 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{{if not (eq .Repository.LFSSize 0)}} tooltip{{end}}"{{if not (eq .Repository.LFSSize 0)}} data-content="git: {{FileSize .Repository.Size}}, lfs: {{FileSize .Repository.LFSSize}}"{{end}}>
19+
<div class="inline field{{if not (eq .Repository.SizeDetails.LFSSize 0)}} tooltip{{end}}"{{if not (eq .Repository.SizeDetails.LFSSize 0)}} data-content="{{.Repository.SizeDetails.String}}"{{end}}>
2020
<label>{{.locale.Tr "repo.repo_size"}}</label>
21-
<span>{{FileSize (Add .Repository.Size .Repository.LFSSize)}}</span>
21+
<span>{{FileSize .Repository.Size}}</span>
2222
</div>
2323
<div class="inline field">
2424
<label>{{.locale.Tr "repo.template"}}</label>

templates/repo/sub_menu.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</div>
1616
{{end}}
1717
<div class="item">
18-
<span class="ui{{if not (eq .Repository.LFSSize 0)}} tooltip{{end}}"{{if not (eq .Repository.LFSSize 0)}} data-content="git: {{FileSize .Repository.Size}}, lfs: {{FileSize .Repository.LFSSize}}"{{end}}>
18+
<span class="ui{{if not (eq .Repository.SizeDetails.LFSSize 0)}} tooltip{{end}}"{{if not (eq .Repository.SizeDetails.LFSSize 0)}} data-content="{{.Repository.SizeDetails.String}}"{{end}}>
1919
{{svg "octicon-database"}}
20-
<b>{{FileSize (Add .Repository.Size .Repository.LFSSize)}}</b>
20+
<span>{{FileSize .Repository.Size}}</span>
2121
</span>
2222
</div>
2323
{{end}}

templates/user/settings/repos.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
<span class="icon">{{svg "octicon-repo"}}</span>
2828
{{end}}
2929
<a class="name" href="{{$repo.Link}}">{{$repo.OwnerName}}/{{$repo.Name}}</a>
30-
<span class="ui{{if not (eq $repo.LFSSize 0)}} tooltip{{end}}"{{if not (eq $repo.LFSSize 0)}} data-content="git: {{FileSize $repo.Size}}, lfs: {{FileSize $repo.LFSSize}}"{{end}}>
31-
{{FileSize (Add $repo.Size $repo.LFSSize)}}
30+
<span class="ui{{if not (eq $repo.SizeDetails.LFSSize 0)}} tooltip{{end}}"{{if not (eq $repo.SizeDetails.LFSSize 0)}} data-content="{{$repo.SizeDetails.String}}"{{end}}>
31+
{{FileSize $repo.Size}}
3232
</span>
3333
{{if $repo.IsFork}}
3434
{{$.locale.Tr "repo.forked_from"}}

0 commit comments

Comments
 (0)