Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  Fix repository adoption on Windows (go-gitea#21646)
  Refactor docs (go-gitea#21627)
  Update "email usage" page to current ver. (1.18) (go-gitea#21649)
  Fix opaque background on mermaid diagrams (go-gitea#21642)
  Merge db.Iterate and IterateObjects (go-gitea#21641)
  Deal with markdown template without metadata (go-gitea#21639)
  [skip ci] Updated translations via Crowdin
  • Loading branch information
zjjhot committed Nov 1, 2022
2 parents c79db93 + f211d23 commit 869a13d
Show file tree
Hide file tree
Showing 37 changed files with 141 additions and 249 deletions.
12 changes: 6 additions & 6 deletions cmd/migrate_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,43 @@ var CmdMigrateStorage = cli.Command{
}

func migrateAttachments(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(attach *repo_model.Attachment) error {
return db.Iterate(ctx, nil, func(ctx context.Context, attach *repo_model.Attachment) error {
_, err := storage.Copy(dstStorage, attach.RelativePath(), storage.Attachments, attach.RelativePath())
return err
})
}

func migrateLFS(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(mo *git_model.LFSMetaObject) error {
return db.Iterate(ctx, nil, func(ctx context.Context, mo *git_model.LFSMetaObject) error {
_, err := storage.Copy(dstStorage, mo.RelativePath(), storage.LFS, mo.RelativePath())
return err
})
}

func migrateAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(user *user_model.User) error {
return db.Iterate(ctx, nil, func(ctx context.Context, user *user_model.User) error {
_, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath())
return err
})
}

func migrateRepoAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(repo *repo_model.Repository) error {
return db.Iterate(ctx, nil, func(ctx context.Context, repo *repo_model.Repository) error {
_, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath())
return err
})
}

func migrateRepoArchivers(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(archiver *repo_model.RepoArchiver) error {
return db.Iterate(ctx, nil, func(ctx context.Context, archiver *repo_model.RepoArchiver) error {
p := archiver.RelativePath()
_, err := storage.Copy(dstStorage, p, storage.RepoArchives, p)
return err
})
}

func migratePackages(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.IterateObjects(ctx, func(pb *packages_model.PackageBlob) error {
return db.Iterate(ctx, nil, func(ctx context.Context, pb *packages_model.PackageBlob) error {
p := packages_module.KeyToRelativePath(packages_module.BlobHash256Key(pb.HashSHA256))
_, err := storage.Copy(dstStorage, p, storage.Packages, p)
return err
Expand Down
43 changes: 0 additions & 43 deletions docs/content/doc/advanced/hacking-on-gitea.zh-cn.md

This file was deleted.

44 changes: 0 additions & 44 deletions docs/content/doc/advanced/make.fr-fr.md

This file was deleted.

45 changes: 0 additions & 45 deletions docs/content/doc/advanced/make.zh-cn.md

This file was deleted.

39 changes: 0 additions & 39 deletions docs/content/doc/advanced/third-party-tools.zh-cn.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/content/doc/developers.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ draft: false
menu:
sidebar:
name: "开发者"
weight: 50
weight: 55
identifier: "developers"
---
2 changes: 1 addition & 1 deletion docs/content/doc/installation/from-source.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ To build from source, the following programs must be present on the system:

- `go` {{< min-go-version >}} or higher, see [here](https://golang.org/dl/)
- `node` {{< min-node-version >}} or higher with `npm`, see [here](https://nodejs.org/en/download/)
- `make`, see <a href='{{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make'>here</a>
- `make`, see [here]({{< relref "doc/developers/hacking-on-gitea.en-us.md" >}}#installing-make)

Various [make tasks](https://github.com/go-gitea/gitea/blob/main/Makefile)
are provided to keep the build process as simple as possible.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/installation/from-source.fr-fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ git checkout pr-xyz

## Compilation

Comme nous regroupons déjà toutes les bibliothèques requises pour compiler Gitea, vous pouvez continuer avec le processus de compilation lui-même. Nous fournissons diverses [tâches Make](https://github.com/go-gitea/gitea/blob/master/Makefile) pour rendre le processus de construction aussi simple que possible. <a href='{{< relref "doc/advanced/make.fr-fr.md" >}}'>Voyez ici comment obtenir Make</a>. Selon vos besoins, vous pourrez éventuellement ajouter diverses options de compilation, vous pouvez choisir entre ces options :
Comme nous regroupons déjà toutes les bibliothèques requises pour compiler Gitea, vous pouvez continuer avec le processus de compilation lui-même. Nous fournissons diverses [tâches Make](https://github.com/go-gitea/gitea/blob/master/Makefile) pour rendre le processus de construction aussi simple que possible. [Voyez ici comment obtenir Make]({{< relref "doc/developers/hacking-on-gitea.fr-fr.md" >}}#installing-make). Selon vos besoins, vous pourrez éventuellement ajouter diverses options de compilation, vous pouvez choisir entre ces options :

* `bindata`: Intègre toutes les ressources nécessaires à l'exécution d'une instance de Gitea, ce qui rend un déploiement facile car il n'est pas nécessaire de se préoccuper des fichiers supplémentaires.
* `sqlite sqlite_unlock_notify`: Active la prise en charge d'une base de données [SQLite3](https://sqlite.org/), ceci n'est recommandé que pour les petites installations de Gitea.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/installation/from-source.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ git checkout v{{< version >}}

- `go` {{< min-go-version >}} 或以上版本, 详见[这里](https://golang.google.cn/doc/install)
- `node` {{< min-node-version >}} 或以上版本,并且安装 `npm`, 详见[这里](https://nodejs.org/zh-cn/download/)
- `make`, 详见[这里]({{< relref "make.zh-cn.md" >}})</a>
- `make`, 详见[这里]({{< relref "doc/developers/hacking-on-gitea.zh-cn.md" >}})</a>

各种可用的 [make 任务](https://github.com/go-gitea/gitea/blob/main/Makefile)
可以用来使编译过程更方便。
Expand Down
6 changes: 4 additions & 2 deletions docs/content/doc/usage/email-setup.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Directly use SMTP server as relay. This option is useful if you don't want to se
ENABLED = true
FROM = gitea@mydomain.com
MAILER_TYPE = smtp
HOST = mail.mydomain.com:587
SMTP_ADDR = mail.mydomain.com
SMTP_PORT = 587
IS_TLS_ENABLED = true
USER = gitea@mydomain.com
PASSWD = `password`
Expand Down Expand Up @@ -75,7 +76,8 @@ The following configuration should work with GMail's SMTP server:
```ini
[mailer]
ENABLED = true
HOST = smtp.gmail.com:465
SMTP_ADDR = smtp.gmail.com
SMTP_PORT = 465
FROM = example@gmail.com
USER = example@gmail.com
PASSWD = ***
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions docs/static/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ https://gitea-docs.netlify.com/* https://docs.gitea.io/:splat 302!

/en-us/ci-cd/ /en-us/integrations/ 302!
/en-us/third-party-tools/ /en-us/integrations/ 302!
/zh-cn/third-party-tools/ /zh-cn/integrations/ 302!
/en-us/make/ /en-us/hacking-on-gitea/ 302!
/zh-cn/make/ /zh-cn/hacking-on-gitea/ 302!
/fr-fr/make/ /fr-fr/hacking-on-gitea/ 302!
/en-us/upgrade/ /en-us/upgrade-from-gitea/ 302!
/fr-fr/upgrade/ /fr-fr/upgrade-from-gitea/ 302!
/zh-cn/upgrade/ /zh-cn/upgrade-from-gitea/ 302!
Expand Down
10 changes: 0 additions & 10 deletions models/db/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"context"
"database/sql"

"code.gitea.io/gitea/modules/setting"

"xorm.io/builder"
"xorm.io/xorm/schemas"
)

Expand Down Expand Up @@ -121,13 +118,6 @@ func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error
return sess.Commit()
}

// Iterate iterates the databases and doing something
func Iterate(ctx context.Context, tableBean interface{}, cond builder.Cond, fun func(idx int, bean interface{}) error) error {
return GetEngine(ctx).Where(cond).
BufferSize(setting.Database.IterateBufferSize).
Iterate(tableBean, fun)
}

// Insert inserts records into database
func Insert(ctx context.Context, beans ...interface{}) error {
_, err := GetEngine(ctx).Insert(beans...)
Expand Down
21 changes: 13 additions & 8 deletions models/db/iterate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@ import (
"context"

"code.gitea.io/gitea/modules/setting"

"xorm.io/builder"
)

// IterateObjects iterate all the Bean object
func IterateObjects[Object any](ctx context.Context, f func(repo *Object) error) error {
// Iterate iterate all the Bean object
func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx context.Context, bean *Bean) error) error {
var start int
batchSize := setting.Database.IterateBufferSize
sess := GetEngine(ctx)
for {
repos := make([]*Object, 0, batchSize)
if err := sess.Limit(batchSize, start).Find(&repos); err != nil {
beans := make([]*Bean, 0, batchSize)
if cond != nil {
sess = sess.Where(cond)
}
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
return err
}
if len(repos) == 0 {
if len(beans) == 0 {
return nil
}
start += len(repos)
start += len(beans)

for _, repo := range repos {
if err := f(repo); err != nil {
for _, bean := range beans {
if err := f(ctx, bean); err != nil {
return err
}
}
Expand Down
44 changes: 44 additions & 0 deletions models/db/iterate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package db_test

import (
"context"
"testing"

"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"

"github.com/stretchr/testify/assert"
)

func TestIterate(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
xe := unittest.GetXORMEngine()
assert.NoError(t, xe.Sync(&repo_model.RepoUnit{}))

var repoCnt int
err := db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repo *repo_model.RepoUnit) error {
repoCnt++
return nil
})
assert.NoError(t, err)
assert.EqualValues(t, 79, repoCnt)

err = db.Iterate(db.DefaultContext, nil, func(ctx context.Context, repoUnit *repo_model.RepoUnit) error {
reopUnit2 := repo_model.RepoUnit{ID: repoUnit.ID}
has, err := db.GetByBean(ctx, &reopUnit2)
if err != nil {
return err
} else if !has {
return db.ErrNotExist{Resource: "repo_unit", ID: repoUnit.ID}
}
assert.EqualValues(t, repoUnit.RepoID, repoUnit.RepoID)
assert.EqualValues(t, repoUnit.CreatedUnix, repoUnit.CreatedUnix)
return nil
})
assert.NoError(t, err)
}
Loading

0 comments on commit 869a13d

Please sign in to comment.