Skip to content

Commit 1ef7f35

Browse files
authored
Merge branch 'master' into only-close-the-gitrepo-at-the-end-of-wrap
2 parents 04a5bb6 + ed39377 commit 1ef7f35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+506
-187
lines changed

custom/conf/app.example.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,14 @@ RUN_AT_START = false
11451145
NO_SUCCESS_NOTICE = false
11461146
SCHEDULE = @every 72h
11471147

1148+
; Delete all old actions from database
1149+
[cron.delete_old_actions]
1150+
ENABLED = false
1151+
RUN_AT_START = false
1152+
NO_SUCCESS_NOTICE = false
1153+
SCHEDULE = @every 168h
1154+
OLDER_THAN = 8760h
1155+
11481156
[git]
11491157
; The path of git executable. If empty, Gitea searches through the PATH environment.
11501158
PATH =

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,13 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
786786
- `NO_SUCCESS_NOTICE`: **false**: Set to true to switch off success notices.
787787
- `SCHEDULE`: **@every 72h**: Cron syntax for scheduling repository archive cleanup, e.g. `@every 1h`.
788788

789+
#### Cron - Delete all old actions from database ('cron.delete_old_actions')
790+
- `ENABLED`: **false**: Enable service.
791+
- `RUN_AT_START`: **false**: Run tasks at start up time (if ENABLED).
792+
- `NO_SUCCESS_NOTICE`: **false**: Set to true to switch off success notices.
793+
- `SCHEDULE`: **@every 128h**: Cron syntax for scheduling a work, e.g. `@every 128h`.
794+
- `OLDER_THAN`: **@every 8760h**: any action older than this expression will be deleted from database, suggest using `8760h` (1 year) because that's the max length of heatmap.
795+
789796
## Git (`git`)
790797

791798
- `PATH`: **""**: The path of git executable. If empty, Gitea searches through the PATH environment.

integrations/mssql.ini.tmpl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ PASSWD = {{TEST_MSSQL_PASSWORD}}
1010
SSL_MODE = disable
1111

1212
[indexer]
13-
ISSUE_INDEXER_PATH = integrations/indexers-mssql/issues.bleve
13+
ISSUE_INDEXER_PATH = integrations/gitea-integration-mssql/indexers/issues.bleve
14+
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mssql/indexers/issues.queue
1415
REPO_INDEXER_ENABLED = true
15-
REPO_INDEXER_PATH = integrations/indexers-mssql/repos.bleve
16+
REPO_INDEXER_PATH = integrations/gitea-integration-mssql/indexers/repos.bleve
1617

1718
[queue.code_indexer]
1819
TYPE = immediate
@@ -24,8 +25,10 @@ TYPE = immediate
2425
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mssql/gitea-repositories
2526

2627
[repository.local]
27-
LOCAL_COPY_PATH = tmp/local-repo-mssql
28-
LOCAL_WIKI_PATH = tmp/local-wiki-mssql
28+
LOCAL_COPY_PATH = integrations/gitea-integration-mssql/tmp/local-repo
29+
30+
[repository.upload]
31+
TEMP_PATH = integrations/gitea-integration-mssql/tmp/uploads
2932

3033
[repository.signing]
3134
SIGNING_KEY = none
@@ -39,14 +42,14 @@ SSH_LISTEN_HOST = localhost
3942
SSH_PORT = 2201
4043
START_SSH_SERVER = true
4144
LFS_START_SERVER = true
42-
LFS_CONTENT_PATH = integrations/gitea-integration-mssql/data/lfs-mssql
45+
LFS_CONTENT_PATH = integrations/gitea-integration-mssql/data/lfs
4346
OFFLINE_MODE = false
4447
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
4548
APP_DATA_PATH = integrations/gitea-integration-mssql/data
4649
BUILTIN_SSH_SERVER_USER = git
4750

4851
[attachment]
49-
PATH = integrations/gitea-integration-mssql/data
52+
PATH = integrations/gitea-integration-mssql/data/attachments
5053

5154
[mailer]
5255
ENABLED = true

integrations/mysql.ini.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ SSL_MODE = disable
1212
[indexer]
1313
ISSUE_INDEXER_TYPE = elasticsearch
1414
ISSUE_INDEXER_CONN_STR = http://elastic:changeme@elasticsearch:9200
15-
ISSUE_INDEXER_PATH = integrations/indexers-mysql/issues.bleve
15+
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mysql/indexers/issues.queue
1616
REPO_INDEXER_ENABLED = true
17-
REPO_INDEXER_PATH = integrations/indexers-mysql/repos.bleve
17+
REPO_INDEXER_PATH = integrations/gitea-integration-mysql/indexers/repos.bleve
1818

1919
[queue.code_indexer]
2020
TYPE = immediate
@@ -26,8 +26,10 @@ TYPE = immediate
2626
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql/gitea-repositories
2727

2828
[repository.local]
29-
LOCAL_COPY_PATH = tmp/local-repo-mysql
30-
LOCAL_WIKI_PATH = tmp/local-wiki-mysql
29+
LOCAL_COPY_PATH = integrations/gitea-integration-mysql/tmp/local-repo
30+
31+
[repository.upload]
32+
TEMP_PATH = integrations/gitea-integration-mysql/tmp/uploads
3133

3234
[repository.signing]
3335
SIGNING_KEY = none

integrations/mysql8.ini.tmpl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ PASSWD = {{TEST_MYSQL8_PASSWORD}}
1010
SSL_MODE = disable
1111

1212
[indexer]
13-
ISSUE_INDEXER_PATH = integrations/indexers-mysql8/issues.bleve
13+
ISSUE_INDEXER_PATH = integrations/gitea-integration-mysql8/indexers/issues.bleve
14+
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-mysql8/indexers/issues.queue
1415
REPO_INDEXER_ENABLED = true
15-
REPO_INDEXER_PATH = integrations/indexers-mysql8/repos.bleve
16+
REPO_INDEXER_PATH = integrations/gitea-integration-mysql8/indexers/repos.bleve
1617

1718
[queue.code_indexer]
1819
TYPE = immediate
@@ -24,8 +25,10 @@ TYPE = immediate
2425
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-mysql8/gitea-repositories
2526

2627
[repository.local]
27-
LOCAL_COPY_PATH = tmp/local-repo-mysql8
28-
LOCAL_WIKI_PATH = tmp/local-wiki-mysql8
28+
LOCAL_COPY_PATH = integrations/gitea-integration-mysql8/tmp/local-repo
29+
30+
[repository.upload]
31+
TEMP_PATH = integrations/gitea-integration-mysql8/tmp/uploads
2932

3033
[repository.signing]
3134
SIGNING_KEY = none
@@ -39,12 +42,15 @@ SSH_LISTEN_HOST = localhost
3942
SSH_PORT = 2204
4043
START_SSH_SERVER = true
4144
LFS_START_SERVER = true
42-
LFS_CONTENT_PATH = data/lfs-mysql8
45+
LFS_CONTENT_PATH = integrations/gitea-integration-mysql8/data/lfs
4346
OFFLINE_MODE = false
4447
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
4548
APP_DATA_PATH = integrations/gitea-integration-mysql8/data
4649
BUILTIN_SSH_SERVER_USER = git
4750

51+
[attachment]
52+
PATH = integrations/gitea-integration-mysql8/data/attachments
53+
4854
[mailer]
4955
ENABLED = false
5056

@@ -60,12 +66,14 @@ DEFAULT_ALLOW_CREATE_ORGANIZATION = true
6066
NO_REPLY_ADDRESS = noreply.example.org
6167

6268
[picture]
63-
DISABLE_GRAVATAR = false
64-
ENABLE_FEDERATED_AVATAR = false
69+
DISABLE_GRAVATAR = false
70+
ENABLE_FEDERATED_AVATAR = false
71+
AVATAR_UPLOAD_PATH = integrations/gitea-integration-mysql8/data/avatars
72+
REPOSITORY_AVATAR_UPLOAD_PATH = integrations/gitea-integration-mysql8/data/repo-avatars
6573

6674
[session]
6775
PROVIDER = file
68-
PROVIDER_CONFIG = data/sessions-mysql8
76+
PROVIDER_CONFIG = integrations/gitea-integration-mysql8/data/sessions
6977

7078
[log]
7179
MODE = test,file
@@ -80,10 +88,8 @@ COLORIZE = true
8088
[log.file]
8189
LEVEL = Debug
8290

83-
8491
[security]
8592
DISABLE_GIT_HOOKS = false
8693
INSTALL_LOCK = true
8794
SECRET_KEY = 9pCviYTWSb
8895
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ
89-

integrations/pgsql.ini.tmpl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ SCHEMA = {{TEST_PGSQL_SCHEMA}}
1111
SSL_MODE = disable
1212

1313
[indexer]
14-
ISSUE_INDEXER_PATH = integrations/indexers-pgsql/issues.bleve
14+
ISSUE_INDEXER_PATH = integrations/gitea-integration-pgsql/indexers/issues.bleve
15+
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-pgsql/indexers/issues.queue
1516
REPO_INDEXER_ENABLED = true
16-
REPO_INDEXER_PATH = integrations/indexers-pgsql/repos.bleve
17+
REPO_INDEXER_PATH = integrations/gitea-integration-pgsql/indexers/repos.bleve
1718

1819
[queue.code_indexer]
1920
TYPE = immediate
@@ -25,8 +26,10 @@ TYPE = immediate
2526
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-pgsql/gitea-repositories
2627

2728
[repository.local]
28-
LOCAL_COPY_PATH = tmp/local-repo-pgsql
29-
LOCAL_WIKI_PATH = tmp/local-wiki-pgsql
29+
LOCAL_COPY_PATH = integrations/gitea-integration-pgsql/tmp/local-repo
30+
31+
[repository.upload]
32+
TEMP_PATH = integrations/gitea-integration-pgsql/tmp/uploads
3033

3134
[repository.signing]
3235
SIGNING_KEY = none
@@ -40,14 +43,14 @@ SSH_LISTEN_HOST = localhost
4043
SSH_PORT = 2202
4144
START_SSH_SERVER = true
4245
LFS_START_SERVER = true
43-
LFS_CONTENT_PATH = integrations/gitea-integration-pgsql/data/lfs-pgsql
46+
LFS_CONTENT_PATH = integrations/gitea-integration-pgsql/data/lfs
4447
OFFLINE_MODE = false
4548
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
4649
APP_DATA_PATH = integrations/gitea-integration-pgsql/data
4750
BUILTIN_SSH_SERVER_USER = git
4851

4952
[attachment]
50-
PATH = integrations/gitea-integration-pgsql/data
53+
PATH = integrations/gitea-integration-pgsql/data/attachments
5154

5255
[mailer]
5356
ENABLED = true

integrations/sqlite.ini.tmpl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ DB_TYPE = sqlite3
66
PATH = integrations/gitea-integration-sqlite/gitea.db
77

88
[indexer]
9-
ISSUE_INDEXER_PATH = integrations/indexers-sqlite/issues.bleve
9+
ISSUE_INDEXER_PATH = integrations/gitea-integration-sqlite/indexers/issues.bleve
10+
ISSUE_INDEXER_QUEUE_DIR = integrations/gitea-integration-sqlite/indexers/issues.queue
1011
REPO_INDEXER_ENABLED = true
11-
REPO_INDEXER_PATH = integrations/indexers-sqlite/repos.bleve
12+
REPO_INDEXER_PATH = integrations/gitea-integration-sqlite/indexers/repos.bleve
1213

1314
[queue.code_indexer]
1415
TYPE = immediate
@@ -20,8 +21,10 @@ TYPE = immediate
2021
ROOT = {{REPO_TEST_DIR}}integrations/gitea-integration-sqlite/gitea-repositories
2122

2223
[repository.local]
23-
LOCAL_COPY_PATH = tmp/local-repo-sqlite
24-
LOCAL_WIKI_PATH = tmp/local-wiki-sqlite
24+
LOCAL_COPY_PATH = integrations/gitea-integration-sqlite/tmp/local-repo
25+
26+
[repository.upload]
27+
TEMP_PATH = integrations/gitea-integration-sqlite/tmp/uploads
2528

2629
[repository.signing]
2730
SIGNING_KEY = none
@@ -35,15 +38,15 @@ SSH_LISTEN_HOST = localhost
3538
SSH_PORT = 2203
3639
START_SSH_SERVER = true
3740
LFS_START_SERVER = true
38-
LFS_CONTENT_PATH = integrations/gitea-integration-sqlite/data
41+
LFS_CONTENT_PATH = integrations/gitea-integration-sqlite/data/lfs
3942
OFFLINE_MODE = false
4043
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w
4144
APP_DATA_PATH = integrations/gitea-integration-sqlite/data
4245
ENABLE_GZIP = true
4346
BUILTIN_SSH_SERVER_USER = git
4447

4548
[attachment]
46-
PATH = integrations/gitea-integration-sqlite/data
49+
PATH = integrations/gitea-integration-sqlite/data/attachments
4750

4851
[mailer]
4952
ENABLED = true
@@ -67,7 +70,6 @@ ENABLE_FEDERATED_AVATAR = false
6770
AVATAR_UPLOAD_PATH = integrations/gitea-integration-sqlite/data/avatars
6871
REPOSITORY_AVATAR_UPLOAD_PATH = integrations/gitea-integration-sqlite/data/repo-avatars
6972

70-
7173
[session]
7274
PROVIDER = file
7375
PROVIDER_CONFIG = integrations/gitea-integration-sqlite/data/sessions

models/action.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,13 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
395395

396396
return cond, nil
397397
}
398+
399+
// DeleteOldActions deletes all old actions from database.
400+
func DeleteOldActions(olderThan time.Duration) (err error) {
401+
if olderThan <= 0 {
402+
return nil
403+
}
404+
405+
_, err = x.Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{})
406+
return
407+
}

models/repo.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,24 +1455,26 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
14551455
if err := deleteBeans(sess,
14561456
&Access{RepoID: repo.ID},
14571457
&Action{RepoID: repo.ID},
1458-
&Watch{RepoID: repoID},
1459-
&Star{RepoID: repoID},
1460-
&Mirror{RepoID: repoID},
1461-
&Milestone{RepoID: repoID},
1462-
&Release{RepoID: repoID},
14631458
&Collaboration{RepoID: repoID},
1464-
&PullRequest{BaseRepoID: repoID},
1465-
&RepoUnit{RepoID: repoID},
1466-
&RepoRedirect{RedirectRepoID: repoID},
1467-
&Webhook{RepoID: repoID},
1459+
&Comment{RefRepoID: repoID},
1460+
&CommitStatus{RepoID: repoID},
1461+
&DeletedBranch{RepoID: repoID},
14681462
&HookTask{RepoID: repoID},
1463+
&LFSLock{RepoID: repoID},
1464+
&LanguageStat{RepoID: repoID},
1465+
&Milestone{RepoID: repoID},
1466+
&Mirror{RepoID: repoID},
14691467
&Notification{RepoID: repoID},
1470-
&CommitStatus{RepoID: repoID},
1468+
&ProtectedBranch{RepoID: repoID},
1469+
&PullRequest{BaseRepoID: repoID},
1470+
&Release{RepoID: repoID},
14711471
&RepoIndexerStatus{RepoID: repoID},
1472-
&LanguageStat{RepoID: repoID},
1473-
&Comment{RefRepoID: repoID},
1472+
&RepoRedirect{RedirectRepoID: repoID},
1473+
&RepoUnit{RepoID: repoID},
1474+
&Star{RepoID: repoID},
14741475
&Task{RepoID: repoID},
1475-
&ProtectedBranch{RepoID: repoID},
1476+
&Watch{RepoID: repoID},
1477+
&Webhook{RepoID: repoID},
14761478
); err != nil {
14771479
return fmt.Errorf("deleteBeans: %v", err)
14781480
}
@@ -1488,10 +1490,6 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
14881490
return err
14891491
}
14901492

1491-
if _, err := sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil {
1492-
return err
1493-
}
1494-
14951493
if repo.IsFork {
14961494
if _, err := sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
14971495
return fmt.Errorf("decrease fork count: %v", err)

models/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ func CountSessions() (int64, error) {
117117

118118
// CleanupSessions cleans up expired sessions
119119
func CleanupSessions(maxLifetime int64) error {
120-
_, err := x.Where("created_unix <= ?", timeutil.TimeStampNow().Add(-maxLifetime)).Delete(&Session{})
120+
_, err := x.Where("expiry <= ?", timeutil.TimeStampNow().Add(-maxLifetime)).Delete(&Session{})
121121
return err
122122
}

modules/convert/user.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.
3838
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
3939
func toUser(user *models.User, signed, authed bool) *api.User {
4040
result := &api.User{
41-
ID: user.ID,
42-
UserName: user.Name,
43-
FullName: markup.Sanitize(user.FullName),
44-
Email: user.GetEmail(),
45-
AvatarURL: user.AvatarLink(),
46-
Created: user.CreatedUnix.AsTime(),
47-
Restricted: user.IsRestricted,
41+
ID: user.ID,
42+
UserName: user.Name,
43+
FullName: markup.Sanitize(user.FullName),
44+
Email: user.GetEmail(),
45+
AvatarURL: user.AvatarLink(),
46+
Created: user.CreatedUnix.AsTime(),
47+
Restricted: user.IsRestricted,
48+
Location: user.Location,
49+
Website: user.Website,
50+
Description: user.Description,
4851
}
4952
// hide primary email if API caller is anonymous or user keep email private
5053
if signed && (!user.KeepEmailPrivate || authed) {

modules/cron/tasks_extended.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@ func registerRemoveRandomAvatars() {
117117
})
118118
}
119119

120+
func registerDeleteOldActions() {
121+
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
122+
BaseConfig: BaseConfig{
123+
Enabled: false,
124+
RunAtStart: false,
125+
Schedule: "@every 168h",
126+
},
127+
OlderThan: 365 * 24 * time.Hour,
128+
}, func(ctx context.Context, _ *models.User, config Config) error {
129+
olderThanConfig := config.(*OlderThanConfig)
130+
return models.DeleteOldActions(olderThanConfig.OlderThan)
131+
})
132+
}
133+
120134
func initExtendedTasks() {
121135
registerDeleteInactiveUsers()
122136
registerDeleteRepositoryArchives()
@@ -127,4 +141,5 @@ func initExtendedTasks() {
127141
registerReinitMissingRepositories()
128142
registerDeleteMissingRepositories()
129143
registerRemoveRandomAvatars()
144+
registerDeleteOldActions()
130145
}

0 commit comments

Comments
 (0)