Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split lfs size from repository size #22900

Merged
merged 41 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b149388
split lfs size from repository size
a1012112796 Feb 14, 2023
63fe364
fix lint
a1012112796 Feb 14, 2023
3df76e7
apply suggestions from code review
a1012112796 Feb 14, 2023
997ce53
adapt return type in `Add` helper function
a1012112796 Feb 14, 2023
292922d
Apply suggestions from code review
a1012112796 Feb 15, 2023
1dfd604
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Feb 15, 2023
a5fb15e
fix lint
a1012112796 Feb 15, 2023
ede9146
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Feb 17, 2023
0c047b3
use repo size detail
a1012112796 Feb 17, 2023
65b7183
revert changs about add
a1012112796 Feb 17, 2023
fb47f0c
rename
a1012112796 Feb 18, 2023
3226830
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Feb 18, 2023
07c2b97
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Feb 25, 2023
d747c1c
change data struct
a1012112796 Feb 25, 2023
383ef59
fix nit
a1012112796 Feb 25, 2023
84236f2
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Feb 28, 2023
8123c6d
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Jun 14, 2023
17b30a5
Merge remote-tracking branch 'upstream/main' into zzc/dev/split_lfs_s…
DmitryFrolovTri Jun 14, 2023
0564958
fix ui
a1012112796 Jun 14, 2023
291e1cd
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Jun 14, 2023
9fd948a
Merge remote-tracking branch 'upstreamlfssize/zzc/dev/split_lfs_size'…
DmitryFrolovTri Jun 15, 2023
f1ede76
Moved tool tip to the center of the number in the repo settings screen
DmitryFrolovTri Jun 16, 2023
52f7d08
Added function to return struct of sizes
DmitryFrolovTri Jun 16, 2023
7b46b63
added constants to represent text names
DmitryFrolovTri Jun 16, 2023
ad93fee
Merge pull request #8 from DmitryFrolovTri/zzc/dev/split_lfs_size_jun…
a1012112796 Jun 16, 2023
c5cf758
split the size in the administrative section repository list
DmitryFrolovTri Jun 16, 2023
d9e2d44
Merge pull request #9 from DmitryFrolovTri/zzc/dev/split_lfs_size_jun…
a1012112796 Jun 16, 2023
753fd1b
Merge remote-tracking branch 'origin/main' into zzc/dev/split_lfs_size
a1012112796 Jun 16, 2023
34bbe1e
fix sort
a1012112796 Jun 16, 2023
8e64230
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Jun 17, 2023
8266317
rename
a1012112796 Jun 17, 2023
8f3be38
Apply suggestions from code review
a1012112796 Jun 19, 2023
0366eff
Merge remote-tracking branch 'origin/main' into zzc/dev/split_lfs_size
a1012112796 Jun 20, 2023
844af9a
update migration
a1012112796 Jun 20, 2023
53c7e2e
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Jun 25, 2023
651dbfd
Merge branch 'main' into zzc/dev/split_lfs_size
a1012112796 Jun 25, 2023
2cc9bf3
Merge remote-tracking branch 'upstream/main' into zzc/dev/split_lfs_s…
DmitryFrolovTri Jun 28, 2023
1a63a59
Merge pull request #12 from DmitryFrolovTri/zzc/dev/split_lfs_size_ju…
a1012112796 Jun 28, 2023
f077e0a
Merge branch 'main' into zzc/dev/split_lfs_size
GiteaBot Jun 28, 2023
8659688
Merge branch 'main' into zzc/dev/split_lfs_size
GiteaBot Jun 28, 2023
4d51de1
Merge branch 'main' into zzc/dev/split_lfs_size
GiteaBot Jun 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions models/db/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ var migrations = []Migration{
NewMigration("Add variable table", v1_21.CreateVariableTable),
// v262 -> v263
NewMigration("Add TriggerEvent to action_run table", v1_21.AddTriggerEventToActionRun),
// v263 -> v264
NewMigration("Add git_size and lfs_size columns to repository table", v1_21.AddGitSizeAndLFSSizeToRepositoryTable),
}

// GetCurrentDBVersion returns the current db version
Expand Down
41 changes: 41 additions & 0 deletions models/migrations/v1_21/v263.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_21 //nolint

import (
"fmt"

"xorm.io/xorm"
)

// AddGitSizeAndLFSSizeToRepositoryTable: add GitSize and LFSSize columns to Repository
func AddGitSizeAndLFSSizeToRepositoryTable(x *xorm.Engine) error {
type Repository struct {
GitSize int64 `xorm:"NOT NULL DEFAULT 0"`
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
}

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()
}
39 changes: 39 additions & 0 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 @@ -163,6 +164,8 @@ type Repository struct {
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
TemplateID int64 `xorm:"INDEX"`
Size int64 `xorm:"NOT NULL DEFAULT 0"`
a1012112796 marked this conversation as resolved.
Show resolved Hide resolved
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"`
Expand Down Expand Up @@ -196,6 +199,42 @@ 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
}

// SizeDetails forms a struct with various size details about repository
func (repo *Repository) SizeDetails() []SizeDetail {
sizeDetails := []SizeDetail{
{
Name: SizeDetailNameGit,
Size: repo.GitSize,
},
{
Name: SizeDetailNameLFS,
Size: repo.LFSSize,
},
}
return sizeDetails
}

// SizeDetailsString returns a concatenation of all repository size details as a string
func (repo *Repository) SizeDetailsString() string {
lunny marked this conversation as resolved.
Show resolved Hide resolved
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 {
if repo == nil {
return "<Repository nil>"
Expand Down
8 changes: 5 additions & 3 deletions models/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +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 int64) error {
_, err := db.GetEngine(ctx).ID(repoID).Cols("size").NoAutoTime().Update(&Repository{
Size: size,
func UpdateRepoSize(ctx context.Context, repoID, gitSize, lfsSize int64) error {
_, err := db.GetEngine(ctx).ID(repoID).Cols("size", "git_size", "lfs_size").NoAutoTime().Update(&Repository{
Size: gitSize + lfsSize,
GitSize: gitSize,
LFSSize: lfsSize,
})
return err
}
2 changes: 1 addition & 1 deletion modules/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ repos.stars = Stars
repos.forks = Forks
repos.issues = Issues
repos.size = Size
repos.lfs_size = LFS Size

packages.package_manage_panel = Package Management
packages.total_size = Total Size: %s
Expand Down
8 changes: 8 additions & 0 deletions routers/web/explore/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
11 changes: 8 additions & 3 deletions templates/admin/repo/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
{{SortArrow "mostforks" "fewestforks" $.SortType false}}
</th>
<th>{{.locale.Tr "admin.repos.issues"}}</th>
<th data-sortt-asc="size" data-sortt-desc="reversesize">
<th data-sortt-asc="gitsize" data-sortt-desc="reversegitsize">
{{.locale.Tr "admin.repos.size"}}
{{SortArrow "size" "reversesize" $.SortType false}}
{{SortArrow "gitsize" "reversegitsize" $.SortType false}}
</th>
<th data-sortt-asc="lfssize" data-sortt-desc="reverselfssize">
{{.locale.Tr "admin.repos.lfs_size"}}
{{SortArrow "lfssize" "reverselfssize" $.SortType false}}
</th>
<th>{{.locale.Tr "admin.auths.updated"}}</th>
<th>{{.locale.Tr "admin.users.created"}}</th>
Expand Down Expand Up @@ -80,7 +84,8 @@
<td>{{.NumStars}}</td>
<td>{{.NumForks}}</td>
<td>{{.NumIssues}}</td>
<td>{{FileSize .Size}}</td>
<td>{{FileSize .GitSize}}</td>
<td>{{FileSize .LFSSize}}</td>
<td>{{DateTime "short" .UpdatedUnix}}</td>
<td>{{DateTime "short" .CreatedUnix}}</td>
<td><a class="delete-button" href="" data-url="{{$.Link}}/delete?page={{$.Page.Paginater.Current}}&sort={{$.SortType}}" data-id="{{.ID}}" data-name="{{.Name}}">{{svg "octicon-trash"}}</a></td>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="inline field">
<label>{{.locale.Tr "repo.repo_size"}}</label>
<span>{{FileSize .Repository.Size}}</span>
<span {{if not (eq .Repository.Size 0)}} data-tooltip-content="{{.Repository.SizeDetailsString}}"{{end}}>{{FileSize .Repository.Size}}</span>
</div>
<div class="inline field">
<label>{{.locale.Tr "repo.template"}}</label>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/sub_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a href="{{.RepoLink}}/tags">{{svg "octicon-tag"}} <b>{{.NumTags}}</b> {{.locale.TrN .NumTags "repo.tag" "repo.tags"}}</a>
</div>
{{end}}
<div class="item">
<div class="item" {{if not (eq .Repository.Size 0)}}data-tooltip-content="{{.Repository.SizeDetailsString}}"{{end}}>
{{$fileSizeFormatted := FileSize .Repository.Size}}{{/* the formatted string is always "{val} {unit}" */}}
{{$fileSizeFields := StringUtils.Split $fileSizeFormatted " "}}
<span>{{svg "octicon-database"}} <b>{{.locale.PrettyNumber (index $fileSizeFields 0)}}</b> {{index $fileSizeFields 1}}</span>
Expand Down
2 changes: 1 addition & 1 deletion templates/user/settings/repos.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<span class="icon">{{svg "octicon-repo"}}</span>
{{end}}
<a class="muted name" href="{{$repo.Link}}">{{$repo.OwnerName}}/{{$repo.Name}}</a>
<span class="text light-3">{{FileSize $repo.Size}}</span>
<span class="text light-3" {{if not (eq $repo.Size 0)}} data-tooltip-content="{{$repo.SizeDetailsString}}"{{end}}>{{FileSize $repo.Size}}</span>
{{if $repo.IsFork}}
{{$.locale.Tr "repo.forked_from"}}
<span><a href="{{$repo.BaseRepo.Link}}">{{$repo.BaseRepo.OwnerName}}/{{$repo.BaseRepo.Name}}</a></span>
Expand Down