From b149388ac75c9d0e2ec10b6d98ce2a21b8ceb339 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 14 Feb 2023 03:54:06 +0000 Subject: [PATCH 01/20] 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 <1012112796@qq.com> --- models/migrations/migrations.go | 2 ++ models/migrations/v1_19/v242.go | 17 +++++++++++++++++ models/repo/repo.go | 1 + models/repo/update.go | 7 ++++--- modules/repository/create.go | 2 +- modules/templates/helper.go | 7 +++++++ services/convert/repository.go | 2 +- templates/repo/settings/options.tmpl | 4 ++-- templates/repo/sub_menu.tmpl | 5 ++++- templates/user/settings/repos.tmpl | 4 +++- 10 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 models/migrations/v1_19/v242.go diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 79e857388165d..edf8ec294a028 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -457,6 +457,8 @@ var migrations = []Migration{ NewMigration("Add actions tables", v1_19.AddActionsTables), // v241 -> v242 NewMigration("Add card_type column to project table", v1_19.AddCardTypeToProjectTable), + // v242 -> v243 + NewMigration("Add lfs_size column to repository table", v1_19.AddLFSSizeToRepositoryTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v242.go b/models/migrations/v1_19/v242.go new file mode 100644 index 0000000000000..21a9a4ceeb9e1 --- /dev/null +++ b/models/migrations/v1_19/v242.go @@ -0,0 +1,17 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_19 //nolint + +import ( + "xorm.io/xorm" +) + +// AddLFSSizeToRepositoryTable: add LFSSize column to Repository +func AddLFSSizeToRepositoryTable(x *xorm.Engine) error { + type Repository struct { + LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` + } + + return x.Sync2(new(Repository)) +} diff --git a/models/repo/repo.go b/models/repo/repo.go index e7ec93a22a416..8ff0d565ffe3e 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -163,6 +163,7 @@ type Repository struct { IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` Size int64 `xorm:"NOT NULL DEFAULT 0"` + LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` StatsIndexerStatus *RepoIndexerStatus `xorm:"-"` IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` diff --git a/models/repo/update.go b/models/repo/update.go index 8dd1097450e4a..59a8ff1c58861 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -185,9 +185,10 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s } // UpdateRepoSize updates the repository size, calculating it using getDirectorySize -func UpdateRepoSize(ctx context.Context, repoID, size int64) error { - _, err := db.GetEngine(ctx).ID(repoID).Cols("size").NoAutoTime().Update(&Repository{ - Size: size, +func UpdateRepoSize(ctx context.Context, repoID, size, lfsSize int64) error { + _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "lfs_size").NoAutoTime().Update(&Repository{ + Size: size, + LFSSize: lfsSize, }) return err } diff --git a/modules/repository/create.go b/modules/repository/create.go index b9a72ad573743..d94185c67e9d5 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -330,7 +330,7 @@ func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error { return fmt.Errorf("updateSize: GetLFSMetaObjects: %w", err) } - return repo_model.UpdateRepoSize(ctx, repo.ID, size+lfsSize) + return repo_model.UpdateRepoSize(ctx, repo.ID, size, lfsSize) } // CheckDaemonExportOK creates/removes git-daemon-export-ok for git-daemon... diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 7afc3aa59bc02..4730a0e119000 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -127,6 +127,13 @@ func NewFuncMap() []template.FuncMap { } return sum }, + "Add64": func(a ...int64) int64 { + sum := int64(0) + for _, val := range a { + sum += val + } + return sum + }, "Mul": func(a ...int) int { sum := 1 for _, val := range a { diff --git a/services/convert/repository.go b/services/convert/repository.go index 3ba604002ef2d..6f4e3c46e520f 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -148,7 +148,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc Template: repo.IsTemplate, Empty: repo.IsEmpty, Archived: repo.IsArchived, - Size: int(repo.Size / 1024), + Size: int((repo.Size + repo.LFSSize) / 1024), Fork: repo.IsFork, Parent: parent, Mirror: repo.IsMirror, diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 283991b71696d..8b812c302849a 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,9 +16,9 @@ -
+
- {{FileSize .Repository.Size}} + {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 54423079616d8..e6fcbab07242e 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,7 +15,10 @@
{{end}}
- {{svg "octicon-database"}} {{FileSize .Repository.Size}} + + {{svg "octicon-database"}} + {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}} +
{{end}}
diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 902b3fb2f33b2..d412541c6ed38 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,7 +27,9 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - {{FileSize $repo.Size}} + + {{FileSize (Add64 $repo.Size $repo.LFSSize)}} + {{if $repo.IsFork}} {{$.locale.Tr "repo.forked_from"}} {{$repo.BaseRepo.OwnerName}}/{{$repo.BaseRepo.Name}} From 63fe364035d9c642e62fb7f3499adc08cb063a78 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 14 Feb 2023 04:13:48 +0000 Subject: [PATCH 02/20] fix lint Signed-off-by: a1012112796 <1012112796@qq.com> --- templates/repo/settings/options.tmpl | 2 +- templates/repo/sub_menu.tmpl | 8 ++++---- templates/user/settings/repos.tmpl | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 8b812c302849a..c91da3f292a22 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,7 +16,7 @@ -
+
{{FileSize (Add64 .Repository.Size .Repository.LFSSize)}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index e6fcbab07242e..5c90912d6fade 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,10 +15,10 @@
{{end}}
- - {{svg "octicon-database"}} - {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}} - + + {{svg "octicon-database"}} + {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}} +
{{end}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index d412541c6ed38..39a76951ca1ce 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,9 +27,9 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - - {{FileSize (Add64 $repo.Size $repo.LFSSize)}} - + + {{FileSize (Add64 $repo.Size $repo.LFSSize)}} + {{if $repo.IsFork}} {{$.locale.Tr "repo.forked_from"}} {{$repo.BaseRepo.OwnerName}}/{{$repo.BaseRepo.Name}} From 3df76e73b355542e9de9c3af1d51a97034e26167 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 14 Feb 2023 10:15:36 +0000 Subject: [PATCH 03/20] apply suggestions from code review - show title when the lfs size isn't zero - merge `Add64` and `Add` helper function Signed-off-by: a1012112796 <1012112796@qq.com> --- modules/templates/helper.go | 22 +++++++++++++--------- templates/repo/settings/options.tmpl | 4 ++-- templates/repo/sub_menu.tmpl | 4 ++-- templates/user/settings/repos.tmpl | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 4730a0e119000..1456e0c213062 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -120,18 +120,22 @@ func NewFuncMap() []template.FuncMap { "Subtract": base.Subtract, "EntryIcon": base.EntryIcon, "MigrationIcon": MigrationIcon, - "Add": func(a ...int) int { - sum := 0 - for _, val := range a { - sum += val - } - return sum - }, - "Add64": func(a ...int64) int64 { + "Add": func(a ...interface{}) int64 { sum := int64(0) + for _, val := range a { - sum += val + switch v := val.(type) { + case int: + sum += int64(v) + case int32: + sum += int64(v) + case int64: + sum += v + default: + return -1 + } } + return sum }, "Mul": func(a ...int) int { diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index c91da3f292a22..a0947df4395d4 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,9 +16,9 @@ -
+
- {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}} + {{FileSize (Add .Repository.Size .Repository.LFSSize)}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 5c90912d6fade..d58c47f3b593b 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,9 +15,9 @@
{{end}}
- + {{svg "octicon-database"}} - {{FileSize (Add64 .Repository.Size .Repository.LFSSize)}} + {{FileSize (Add .Repository.Size .Repository.LFSSize)}}
{{end}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 39a76951ca1ce..2eb76f1cee22c 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,8 +27,8 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - - {{FileSize (Add64 $repo.Size $repo.LFSSize)}} + + {{FileSize (Add $repo.Size $repo.LFSSize)}} {{if $repo.IsFork}} {{$.locale.Tr "repo.forked_from"}} From 997ce53b98255786943c7a71fc4fc3a68b1f2f95 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 14 Feb 2023 11:33:37 +0000 Subject: [PATCH 04/20] adapt return type in `Add` helper function Signed-off-by: a1012112796 <1012112796@qq.com> --- modules/templates/helper.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 1456e0c213062..4923732e93dc4 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -120,7 +120,7 @@ func NewFuncMap() []template.FuncMap { "Subtract": base.Subtract, "EntryIcon": base.EntryIcon, "MigrationIcon": MigrationIcon, - "Add": func(a ...interface{}) int64 { + "Add": func(a ...interface{}) interface{} { sum := int64(0) for _, val := range a { @@ -136,6 +136,15 @@ func NewFuncMap() []template.FuncMap { } } + if len(a) > 0 { + switch a[0].(type) { + case int: + return int(sum) + case int32: + return int32(sum) + } + } + return sum }, "Mul": func(a ...int) int { From 292922df67bfcd074ec511ab19f1ed4aaeecdc32 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 15 Feb 2023 19:00:30 +0800 Subject: [PATCH 05/20] Apply suggestions from code review Co-authored-by: Lunny Xiao Co-authored-by: silverwind --- models/repo/repo.go | 1 + templates/repo/settings/options.tmpl | 2 +- templates/repo/sub_menu.tmpl | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 8ff0d565ffe3e..6c0239151575c 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -162,6 +162,7 @@ type Repository struct { BaseRepo *Repository `xorm:"-"` IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` + // the size of git repository directory itself, not include lfs/package/attachment size Size int64 `xorm:"NOT NULL DEFAULT 0"` LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index a0947df4395d4..8d03bf3b430ec 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,7 +16,7 @@
-
+
{{FileSize (Add .Repository.Size .Repository.LFSSize)}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index d58c47f3b593b..93d97cbd6d4f4 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,7 +15,7 @@
{{end}}
- + {{svg "octicon-database"}} {{FileSize (Add .Repository.Size .Repository.LFSSize)}} From a5fb15ea5cfbef0023ba0e9e8cc8ff8cf66c339a Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 15 Feb 2023 11:16:27 +0000 Subject: [PATCH 06/20] fix lint Signed-off-by: a1012112796 <1012112796@qq.com> --- models/repo/repo.go | 12 ++++++------ templates/user/settings/repos.tmpl | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 6c0239151575c..a06ae72690b8a 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -157,12 +157,12 @@ type Repository struct { Units []*RepoUnit `xorm:"-"` PrimaryLanguage *LanguageStat `xorm:"-"` - IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` - ForkID int64 `xorm:"INDEX"` - BaseRepo *Repository `xorm:"-"` - IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` - TemplateID int64 `xorm:"INDEX"` - // the size of git repository directory itself, not include lfs/package/attachment size + IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` + ForkID int64 `xorm:"INDEX"` + BaseRepo *Repository `xorm:"-"` + IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` + TemplateID int64 `xorm:"INDEX"` + // the size of git repository directory itself, not include lfs/package/attachment size Size int64 `xorm:"NOT NULL DEFAULT 0"` LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 2eb76f1cee22c..0557042364991 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,7 +27,7 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - + {{FileSize (Add $repo.Size $repo.LFSSize)}} {{if $repo.IsFork}} From 0c047b39ec81595d96bf7c006ef77f63dc01238d Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 17 Feb 2023 09:53:40 +0000 Subject: [PATCH 07/20] use repo size detail Signed-off-by: a1012112796 <1012112796@qq.com> --- models/migrations/migrations.go | 2 +- models/migrations/v1_19/v243.go | 12 +++++++++--- models/repo/repo.go | 25 ++++++++++++++++++------- models/repo/update.go | 9 ++++++--- services/convert/repository.go | 2 +- templates/repo/settings/options.tmpl | 4 ++-- templates/repo/sub_menu.tmpl | 4 ++-- templates/user/settings/repos.tmpl | 4 ++-- 8 files changed, 41 insertions(+), 21 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 0fc9dc42ee208..c0feb6d9e3e19 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -460,7 +460,7 @@ var migrations = []Migration{ // v242 -> v243 NewMigration("Alter gpg_key_import content TEXT field to MEDIUMTEXT", v1_19.AlterPublicGPGKeyImportContentFieldToMediumText), // v243 -> v244 - NewMigration("Add lfs_size column to repository table", v1_19.AddLFSSizeToRepositoryTable), + NewMigration("Add size_details column to repository table", v1_19.AddSizeDetailsToRepositoryTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_19/v243.go b/models/migrations/v1_19/v243.go index 21a9a4ceeb9e1..8ea2f112bda7f 100644 --- a/models/migrations/v1_19/v243.go +++ b/models/migrations/v1_19/v243.go @@ -7,10 +7,16 @@ import ( "xorm.io/xorm" ) -// AddLFSSizeToRepositoryTable: add LFSSize column to Repository -func AddLFSSizeToRepositoryTable(x *xorm.Engine) error { +type SizeDetails struct { + GitSize int64 + LFSSize int64 + // TODO: size of more parts. +} + +// AddSizeDetailsToRepositoryTable: add LFSSize column to Repository +func AddSizeDetailsToRepositoryTable(x *xorm.Engine) error { type Repository struct { - LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` + SizeDetails SizeDetails `xorm:"TEXT JSON"` } return x.Sync2(new(Repository)) diff --git a/models/repo/repo.go b/models/repo/repo.go index a06ae72690b8a..5ceaf0b817797 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" @@ -112,6 +113,17 @@ const ( RepositoryBroken // repository is in a permanently broken state ) +// SizeDetails represents size of each part for a Repository +type SizeDetails struct { + GitSize int64 + LFSSize int64 + // TODO: size of more parts. +} + +func (s SizeDetails) String() string { + return fmt.Sprintf("git: " + base.FileSize(s.GitSize) + ", lfs: " + base.FileSize(s.LFSSize)) +} + // Repository represents a git repository. type Repository struct { ID int64 `xorm:"pk autoincr"` @@ -157,14 +169,13 @@ type Repository struct { Units []*RepoUnit `xorm:"-"` PrimaryLanguage *LanguageStat `xorm:"-"` - IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` - ForkID int64 `xorm:"INDEX"` - BaseRepo *Repository `xorm:"-"` - IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` - TemplateID int64 `xorm:"INDEX"` - // the size of git repository directory itself, not include lfs/package/attachment size + IsFork bool `xorm:"INDEX NOT NULL DEFAULT false"` + ForkID int64 `xorm:"INDEX"` + BaseRepo *Repository `xorm:"-"` + IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` + TemplateID int64 `xorm:"INDEX"` Size int64 `xorm:"NOT NULL DEFAULT 0"` - LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` + SizeDetails SizeDetails `xorm:"TEXT JSON"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` StatsIndexerStatus *RepoIndexerStatus `xorm:"-"` IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` diff --git a/models/repo/update.go b/models/repo/update.go index 59a8ff1c58861..4374e2d3323f8 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -186,9 +186,12 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s // UpdateRepoSize updates the repository size, calculating it using getDirectorySize func UpdateRepoSize(ctx context.Context, repoID, size, lfsSize int64) error { - _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "lfs_size").NoAutoTime().Update(&Repository{ - Size: size, - LFSSize: lfsSize, + _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "size_details").NoAutoTime().Update(&Repository{ + Size: size + lfsSize, + SizeDetails: SizeDetails{ + GitSize: size, + LFSSize: lfsSize, + }, }) return err } diff --git a/services/convert/repository.go b/services/convert/repository.go index b6599ed2627c6..5db68e837934d 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -148,7 +148,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, mode perm.Acc Template: repo.IsTemplate, Empty: repo.IsEmpty, Archived: repo.IsArchived, - Size: int((repo.Size + repo.LFSSize) / 1024), + Size: int(repo.Size / 1024), Fork: repo.IsFork, Parent: parent, Mirror: repo.IsMirror, diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 997ddedeb9de1..7011161b6875d 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,9 +16,9 @@
-
+
- {{FileSize (Add .Repository.Size .Repository.LFSSize)}} + {{FileSize .Repository.Size}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 93d97cbd6d4f4..2f61de73725cd 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,9 +15,9 @@
{{end}}
- + {{svg "octicon-database"}} - {{FileSize (Add .Repository.Size .Repository.LFSSize)}} + {{FileSize .Repository.Size}}
{{end}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 0557042364991..3b641f87877c2 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,8 +27,8 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - - {{FileSize (Add $repo.Size $repo.LFSSize)}} + + {{FileSize $repo.Size}} {{if $repo.IsFork}} {{$.locale.Tr "repo.forked_from"}} From 65b7183990f3d65d9a359a7a91b52dab3dd087a1 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 17 Feb 2023 10:08:07 +0000 Subject: [PATCH 08/20] revert changs about add Signed-off-by: a1012112796 <1012112796@qq.com> --- modules/templates/helper.go | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index ae2963472e887..8f8f565c1f141 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -119,31 +119,11 @@ func NewFuncMap() []template.FuncMap { "Subtract": base.Subtract, "EntryIcon": base.EntryIcon, "MigrationIcon": MigrationIcon, - "Add": func(a ...interface{}) interface{} { - sum := int64(0) - + "Add": func(a ...int) int { + sum := 0 for _, val := range a { - switch v := val.(type) { - case int: - sum += int64(v) - case int32: - sum += int64(v) - case int64: - sum += v - default: - return -1 - } - } - - if len(a) > 0 { - switch a[0].(type) { - case int: - return int(sum) - case int32: - return int32(sum) - } + sum += val } - return sum }, "Mul": func(a ...int) int { From fb47f0c063f04197fb13b3cb60f10b70cd9ffd23 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 18 Feb 2023 09:35:33 +0000 Subject: [PATCH 09/20] rename Signed-off-by: a1012112796 <1012112796@qq.com> --- models/repo/update.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/repo/update.go b/models/repo/update.go index 4374e2d3323f8..d6f8d8abef457 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -185,11 +185,11 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s } // UpdateRepoSize updates the repository size, calculating it using getDirectorySize -func UpdateRepoSize(ctx context.Context, repoID, size, lfsSize int64) error { +func UpdateRepoSize(ctx context.Context, repoID, gitSize, lfsSize int64) error { _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "size_details").NoAutoTime().Update(&Repository{ - Size: size + lfsSize, + Size: gitSize + lfsSize, SizeDetails: SizeDetails{ - GitSize: size, + GitSize: gitSize, LFSSize: lfsSize, }, }) From d747c1caea5240458318de6b81ce1adef5c3b24c Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 25 Feb 2023 09:32:46 +0000 Subject: [PATCH 10/20] change data struct Signed-off-by: a1012112796 <1012112796@qq.com> --- models/migrations/migrations.go | 2 +- models/migrations/v1_20/v245.go | 13 ++++--------- models/repo/repo.go | 18 ++++++------------ models/repo/update.go | 10 ++++------ templates/repo/settings/options.tmpl | 2 +- templates/repo/sub_menu.tmpl | 2 +- templates/user/settings/repos.tmpl | 2 +- 7 files changed, 18 insertions(+), 31 deletions(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index ab3b0e803330a..fc67bfcd8b905 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -468,7 +468,7 @@ var migrations = []Migration{ // v244 -> v245 NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), // v245 -> v246 - NewMigration("Add size_details column to repository table", v1_20.AddSizeDetailsToRepositoryTable), + NewMigration("Add size_details column to repository table", v1_20.AddGitSizeAndLFSSizeToRepositoryTable), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_20/v245.go b/models/migrations/v1_20/v245.go index bf1f8cd2c95d7..97a101c36a5e6 100644 --- a/models/migrations/v1_20/v245.go +++ b/models/migrations/v1_20/v245.go @@ -7,16 +7,11 @@ import ( "xorm.io/xorm" ) -type SizeDetails struct { - GitSize int64 - LFSSize int64 - // TODO: size of more parts. -} - -// AddSizeDetailsToRepositoryTable: add LFSSize column to Repository -func AddSizeDetailsToRepositoryTable(x *xorm.Engine) error { +// AddGitSizeAndLFSSizeToRepositoryTable: add GitSize and LFSSize columns to Repository +func AddGitSizeAndLFSSizeToRepositoryTable(x *xorm.Engine) error { type Repository struct { - SizeDetails SizeDetails `xorm:"TEXT JSON"` + GitSize int64 `xorm:"NOT NULL DEFAULT 0"` + LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` } return x.Sync2(new(Repository)) diff --git a/models/repo/repo.go b/models/repo/repo.go index eb6d8137f60e4..61d5e1c700880 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -113,17 +113,6 @@ const ( RepositoryBroken // repository is in a permanently broken state ) -// SizeDetails represents size of each part for a Repository -type SizeDetails struct { - GitSize int64 - LFSSize int64 - // TODO: size of more parts. -} - -func (s SizeDetails) String() string { - return fmt.Sprintf("git: " + base.FileSize(s.GitSize) + ", lfs: " + base.FileSize(s.LFSSize)) -} - // Repository represents a git repository. type Repository struct { ID int64 `xorm:"pk autoincr"` @@ -175,7 +164,8 @@ type Repository struct { IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` Size int64 `xorm:"NOT NULL DEFAULT 0"` - SizeDetails SizeDetails `xorm:"TEXT JSON"` + GitSize int64 `xorm:"NOT NULL DEFAULT 0"` + LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` StatsIndexerStatus *RepoIndexerStatus `xorm:"-"` IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` @@ -208,6 +198,10 @@ func (repo *Repository) SanitizedOriginalURL() string { return u.String() } +func (repo *Repository) SizeDetailsString() string { + return fmt.Sprintf("git: " + base.FileSize(repo.GitSize) + ", lfs: " + base.FileSize(repo.LFSSize)) +} + // ColorFormat returns a colored string to represent this repo func (repo *Repository) ColorFormat(s fmt.State) { if repo == nil { diff --git a/models/repo/update.go b/models/repo/update.go index fc94573e22134..d6a42b02b354a 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -186,12 +186,10 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s // UpdateRepoSize updates the repository size, calculating it using getDirectorySize func UpdateRepoSize(ctx context.Context, repoID, gitSize, lfsSize int64) error { - _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "size_details").NoAutoTime().Update(&Repository{ - Size: gitSize + lfsSize, - SizeDetails: SizeDetails{ - GitSize: gitSize, - LFSSize: lfsSize, - }, + _, err := db.GetEngine(ctx).ID(repoID).Cols("size", "git_size", "lfs_size").NoAutoTime().Update(&Repository{ + Size: gitSize + lfsSize, + GitSize: gitSize, + LFSSize: lfsSize, }) return err } diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 7011161b6875d..2b1dc90b27332 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -16,7 +16,7 @@
-
+
{{FileSize .Repository.Size}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 9a9c8f93952c7..6fab3d5bd2f58 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -15,7 +15,7 @@
{{end}}
- + {{svg "octicon-database"}} {{FileSize .Repository.Size}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 3b641f87877c2..5161b42295ad5 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -27,7 +27,7 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - + {{FileSize $repo.Size}} {{if $repo.IsFork}} From 383ef59b2c31653f386a8239e69be1533ef3897d Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 25 Feb 2023 09:35:01 +0000 Subject: [PATCH 11/20] fix nit Signed-off-by: a1012112796 <1012112796@qq.com> --- models/migrations/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index fc67bfcd8b905..1e7c70d1c4f3d 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -468,7 +468,7 @@ var migrations = []Migration{ // v244 -> v245 NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), // v245 -> v246 - NewMigration("Add size_details column to repository table", v1_20.AddGitSizeAndLFSSizeToRepositoryTable), + NewMigration("Add git_size and lfs_size columns to repository table", v1_20.AddGitSizeAndLFSSizeToRepositoryTable), } // GetCurrentDBVersion returns the current db version From 0564958ec6e4f7b7cff069d7b399fb49730ae5ed Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 14 Jun 2023 14:10:07 +0000 Subject: [PATCH 12/20] fix ui Signed-off-by: a1012112796 <1012112796@qq.com> --- templates/repo/settings/options.tmpl | 2 +- templates/repo/sub_menu.tmpl | 2 +- templates/user/settings/repos.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index a703ad1d9b56f..36d59debf0595 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -12,7 +12,7 @@
-
+
{{FileSize .Repository.Size}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 5fbb698aab46b..cc6a11e23ca11 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -14,7 +14,7 @@ {{svg "octicon-tag"}} {{.NumTags}} {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}
{{end}} -
+
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}} {{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}} {{svg "octicon-database"}} {{.locale.PrettyNumber (index $fileSizeFields 0)}} {{index $fileSizeFields 1}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index 7191d7b6fbf8c..6f6e523f871dd 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -24,7 +24,7 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - + {{FileSize $repo.Size}} {{if $repo.IsFork}} From f1ede7632c803ba354ae3a5007bd1f31de015ec1 Mon Sep 17 00:00:00 2001 From: DmitryFrolovTri <23313323+DmitryFrolovTri@users.noreply.github.com> Date: Fri, 16 Jun 2023 06:46:47 +0000 Subject: [PATCH 13/20] Moved tool tip to the center of the number in the repo settings screen --- templates/repo/settings/options.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 36d59debf0595..87fc77c06cfa6 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -12,9 +12,9 @@
-
+
- {{FileSize .Repository.Size}} + {{FileSize .Repository.Size}}
From 52f7d086529584b623439014c1adbdc52faf310d Mon Sep 17 00:00:00 2001 From: DmitryFrolovTri <23313323+DmitryFrolovTri@users.noreply.github.com> Date: Fri, 16 Jun 2023 06:50:35 +0000 Subject: [PATCH 14/20] Added function to return struct of sizes --- models/repo/repo.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 464b30a532b65..9cd7faf53eca4 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -199,8 +199,34 @@ func (repo *Repository) SanitizedOriginalURL() string { return u.String() } +type SizeDetail struct { + Name string + Size int64 +} + +// SizeDetails forms a struct with various size details about repository +func (repo *Repository) SizeDetails() []SizeDetail { + sizeDetails := []SizeDetail{ + { + Name: "git", + Size: repo.GitSize, + }, + { + Name: "lfs", + Size: repo.LFSSize, + }, + } + return sizeDetails +} + +// SizeDetailsString returns a concatenation of all repository size details as a string func (repo *Repository) SizeDetailsString() string { - return fmt.Sprintf("git: " + base.FileSize(repo.GitSize) + ", lfs: " + base.FileSize(repo.LFSSize)) + var str strings.Builder + sizeDetails := repo.SizeDetails() + for _, detail := range sizeDetails { + str.WriteString(fmt.Sprintf("%s: %s, ", detail.Name, base.FileSize(detail.Size))) + } + return strings.TrimSuffix(str.String(), ", ") } func (repo *Repository) LogString() string { From 7b46b638388e9245b797a2d02c57e0d434c443c4 Mon Sep 17 00:00:00 2001 From: DmitryFrolovTri <23313323+DmitryFrolovTri@users.noreply.github.com> Date: Fri, 16 Jun 2023 07:20:23 +0000 Subject: [PATCH 15/20] added constants to represent text names --- models/repo/repo.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 9cd7faf53eca4..b7c02057c2728 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -199,6 +199,12 @@ func (repo *Repository) SanitizedOriginalURL() string { return u.String() } +// text representations to be returned in SizeDetail.Name +const ( + SizeDetailNameGit = "git" + SizeDetailNameLFS = "lfs" +) + type SizeDetail struct { Name string Size int64 @@ -208,11 +214,11 @@ type SizeDetail struct { func (repo *Repository) SizeDetails() []SizeDetail { sizeDetails := []SizeDetail{ { - Name: "git", + Name: SizeDetailNameGit, Size: repo.GitSize, }, { - Name: "lfs", + Name: SizeDetailNameLFS, Size: repo.LFSSize, }, } From c5cf758c3f42d028438c2d7cd3933988ec3ed68c Mon Sep 17 00:00:00 2001 From: DmitryFrolovTri <23313323+DmitryFrolovTri@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:36:27 +0000 Subject: [PATCH 16/20] split the size in the administrative section repository list --- options/locale/locale_en-US.ini | 1 + templates/admin/repo/list.tmpl | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index db5a45f6127c6..ef7e75cd24b92 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2789,6 +2789,7 @@ repos.stars = Stars repos.forks = Forks repos.issues = Issues repos.size = Size +repos.lfssize = LFS Size packages.package_manage_panel = Package Management packages.total_size = Total Size: %s diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index f485784d0c684..845bbdf3ec707 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -33,6 +33,10 @@ {{.locale.Tr "admin.repos.size"}} {{SortArrow "size" "reversesize" $.SortType false}} + + {{.locale.Tr "admin.repos.lfssize"}} + {{SortArrow "size" "reversesize" $.SortType false}} + {{.locale.Tr "admin.auths.updated"}} {{.locale.Tr "admin.users.created"}} {{.locale.Tr "admin.notices.op"}} @@ -80,7 +84,8 @@ {{.NumStars}} {{.NumForks}} {{.NumIssues}} - {{FileSize .Size}} + {{FileSize .GitSize}} + {{FileSize .LFSSize}} {{DateTime "short" .UpdatedUnix}} {{DateTime "short" .CreatedUnix}} {{svg "octicon-trash"}} From 34bbe1e38010240a9e8235d9cb14b171074fcf5b Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 16 Jun 2023 14:25:52 +0000 Subject: [PATCH 17/20] fix sort Signed-off-by: a1012112796 <1012112796@qq.com> --- models/db/search.go | 4 ++++ options/locale/locale_en-US.ini | 4 ++-- routers/web/explore/repo.go | 8 ++++++++ templates/admin/repo/list.tmpl | 12 ++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/models/db/search.go b/models/db/search.go index 105cb64c41511..aa577f08e0439 100644 --- a/models/db/search.go +++ b/models/db/search.go @@ -20,6 +20,10 @@ const ( SearchOrderByNewest SearchOrderBy = "created_unix DESC" SearchOrderBySize SearchOrderBy = "size ASC" SearchOrderBySizeReverse SearchOrderBy = "size DESC" + SearchOrderByGitSize SearchOrderBy = "git_size ASC" + SearchOrderByGitSizeReverse SearchOrderBy = "git_size DESC" + SearchOrderByLFSSize SearchOrderBy = "lfs_size ASC" + SearchOrderByLFSSizeReverse SearchOrderBy = "lfs_size DESC" SearchOrderByID SearchOrderBy = "id ASC" SearchOrderByIDReverse SearchOrderBy = "id DESC" SearchOrderByStars SearchOrderBy = "num_stars ASC" diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index bf5795d201dc0..fc25a1c2e8a62 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2789,8 +2789,8 @@ repos.watches = Watches repos.stars = Stars repos.forks = Forks repos.issues = Issues -repos.size = Size -repos.lfssize = LFS Size +repos.git_size = Git Size +repos.lfs_size = LFS Size packages.package_manage_panel = Package Management packages.total_size = Total Size: %s diff --git a/routers/web/explore/repo.go b/routers/web/explore/repo.go index be5ad1b015b79..e5f7977abd01e 100644 --- a/routers/web/explore/repo.go +++ b/routers/web/explore/repo.go @@ -73,6 +73,14 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { orderBy = db.SearchOrderBySizeReverse case "size": orderBy = db.SearchOrderBySize + case "reversegitsize": + orderBy = db.SearchOrderByGitSizeReverse + case "gitsize": + orderBy = db.SearchOrderByGitSize + case "reverselfssize": + orderBy = db.SearchOrderByLFSSizeReverse + case "lfssize": + orderBy = db.SearchOrderByLFSSize case "moststars": orderBy = db.SearchOrderByStarsReverse case "feweststars": diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 845bbdf3ec707..e453420ccdcde 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -29,13 +29,13 @@ {{SortArrow "mostforks" "fewestforks" $.SortType false}} {{.locale.Tr "admin.repos.issues"}} - - {{.locale.Tr "admin.repos.size"}} - {{SortArrow "size" "reversesize" $.SortType false}} + + {{.locale.Tr "admin.repos.git_size"}} + {{SortArrow "gitsize" "reversegitsize" $.SortType false}} - - {{.locale.Tr "admin.repos.lfssize"}} - {{SortArrow "size" "reversesize" $.SortType false}} + + {{.locale.Tr "admin.repos.lfs_size"}} + {{SortArrow "lfssize" "reverselfssize" $.SortType false}} {{.locale.Tr "admin.auths.updated"}} {{.locale.Tr "admin.users.created"}} From 82663171a9c8ceda70d16678228cd3e13f7febb8 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Sat, 17 Jun 2023 11:45:05 +0000 Subject: [PATCH 18/20] rename Signed-off-by: a1012112796 <1012112796@qq.com> --- options/locale/locale_en-US.ini | 2 +- templates/admin/repo/list.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fc25a1c2e8a62..83e244fcce99f 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2789,7 +2789,7 @@ repos.watches = Watches repos.stars = Stars repos.forks = Forks repos.issues = Issues -repos.git_size = Git Size +repos.size = Size repos.lfs_size = LFS Size packages.package_manage_panel = Package Management diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index e453420ccdcde..3cd8f08f51b11 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -30,7 +30,7 @@ {{.locale.Tr "admin.repos.issues"}} - {{.locale.Tr "admin.repos.git_size"}} + {{.locale.Tr "admin.repos.size"}} {{SortArrow "gitsize" "reversegitsize" $.SortType false}} From 8f3be38f7e34c2eecabcd68ab1da17d19c3a41f7 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Mon, 19 Jun 2023 22:29:42 +0800 Subject: [PATCH 19/20] Apply suggestions from code review Co-authored-by: Lunny Xiao --- templates/repo/settings/options.tmpl | 2 +- templates/repo/sub_menu.tmpl | 2 +- templates/user/settings/repos.tmpl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index 9fea54f4913c9..8c394d5bf5908 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -14,7 +14,7 @@
- {{FileSize .Repository.Size}} + {{FileSize .Repository.Size}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index cc6a11e23ca11..fbff7cfd29126 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -14,7 +14,7 @@ {{svg "octicon-tag"}} {{.NumTags}} {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}
{{end}} -
+
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}} {{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}} {{svg "octicon-database"}} {{.locale.PrettyNumber (index $fileSizeFields 0)}} {{index $fileSizeFields 1}} diff --git a/templates/user/settings/repos.tmpl b/templates/user/settings/repos.tmpl index ea845d792be4c..de29a489bfdcd 100644 --- a/templates/user/settings/repos.tmpl +++ b/templates/user/settings/repos.tmpl @@ -24,7 +24,7 @@ {{svg "octicon-repo"}} {{end}} {{$repo.OwnerName}}/{{$repo.Name}} - + {{FileSize $repo.Size}} {{if $repo.IsFork}} From 844af9a7234804151be258ed87e3c31f9ab97b01 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 20 Jun 2023 09:45:53 +0000 Subject: [PATCH 20/20] update migration Signed-off-by: a1012112796 <1012112796@qq.com> --- models/migrations/v1_21/v261.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/models/migrations/v1_21/v261.go b/models/migrations/v1_21/v261.go index d79ff0f5d91f8..88a5cb92b49fb 100644 --- a/models/migrations/v1_21/v261.go +++ b/models/migrations/v1_21/v261.go @@ -4,6 +4,8 @@ package v1_21 //nolint import ( + "fmt" + "xorm.io/xorm" ) @@ -14,5 +16,26 @@ func AddGitSizeAndLFSSizeToRepositoryTable(x *xorm.Engine) error { LFSSize int64 `xorm:"NOT NULL DEFAULT 0"` } - return x.Sync2(new(Repository)) + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + if err := sess.Sync2(new(Repository)); err != nil { + return fmt.Errorf("Sync2: %w", err) + } + + _, err := sess.Exec(`UPDATE repository SET lfs_size=(SELECT SUM(size) FROM lfs_meta_object WHERE lfs_meta_object.repository_id=repository.ID) WHERE EXISTS (SELECT 1 FROM lfs_meta_object WHERE lfs_meta_object.repository_id=repository.ID)`) + if err != nil { + return err + } + + _, err = sess.Exec(`UPDATE repository SET git_size = size - lfs_size`) + if err != nil { + return err + } + + return sess.Commit() }