Skip to content

Commit

Permalink
use repo size detail
Browse files Browse the repository at this point in the history
Signed-off-by: a1012112796 <[email protected]>
  • Loading branch information
a1012112796 committed Feb 17, 2023
1 parent ede9146 commit 0c047b3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions models/migrations/v1_19/v243.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 18 additions & 7 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
9 changes: 6 additions & 3 deletions models/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion services/convert/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
<input id="repo_name" name="repo_name" value="{{.Repository.Name}}" data-repo-name="{{.Repository.Name}}" autofocus required>
</div>
<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}}>
<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}}>
<label>{{.locale.Tr "repo.repo_size"}}</label>
<span>{{FileSize (Add .Repository.Size .Repository.LFSSize)}}</span>
<span>{{FileSize .Repository.Size}}</span>
</div>
<div class="inline field">
<label>{{.locale.Tr "repo.template"}}</label>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/sub_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
</div>
{{end}}
<div class="item">
<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}}>
<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}}>
{{svg "octicon-database"}}
<b>{{FileSize (Add .Repository.Size .Repository.LFSSize)}}</b>
<span>{{FileSize .Repository.Size}}</span>
</span>
</div>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions templates/user/settings/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<span class="icon">{{svg "octicon-repo"}}</span>
{{end}}
<a class="name" href="{{$repo.Link}}">{{$repo.OwnerName}}/{{$repo.Name}}</a>
<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}}>
{{FileSize (Add $repo.Size $repo.LFSSize)}}
<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}}>
{{FileSize $repo.Size}}
</span>
{{if $repo.IsFork}}
{{$.locale.Tr "repo.forked_from"}}
Expand Down

0 comments on commit 0c047b3

Please sign in to comment.