Skip to content

Commit 3903fe8

Browse files
authored
Merge branch 'go-gitea:main' into main
2 parents d3e844e + 2f725cb commit 3903fe8

File tree

13 files changed

+248
-17
lines changed

13 files changed

+248
-17
lines changed

Dockerfile.rootless

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ COPY docker/rootless /
5656
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
5757
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
5858

59-
USER 1000:1000 # git:git
59+
#git:git
60+
USER 1000:1000
6061
ENV GITEA_WORK_DIR /var/lib/gitea
6162
ENV GITEA_CUSTOM /var/lib/gitea/custom
6263
ENV GITEA_TEMP /tmp/gitea

custom/conf/app.example.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ PATH =
14711471
;; if the cache enabled
14721472
;ENABLED = true
14731473
;;
1474-
;; Either "memory", "redis", or "memcache", default is "memory"
1474+
;; Either "memory", "redis", "memcache", or "twoqueue". default is "memory"
14751475
;ADAPTER = memory
14761476
;;
14771477
;; For "memory" only, GC interval in seconds, default is 60
@@ -1480,6 +1480,7 @@ PATH =
14801480
;; For "redis" and "memcache", connection host address
14811481
;; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180
14821482
;; memcache: `127.0.0.1:11211`
1483+
;; twoqueue: `{"size":50000,"recent_ratio":0.25,"ghost_ratio":0.5}` or `50000`
14831484
;HOST =
14841485
;;
14851486
;; Time to keep items in cache if not used, default is 16 hours.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,12 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
590590
## Cache (`cache`)
591591

592592
- `ENABLED`: **true**: Enable the cache.
593-
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`.
594-
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only.
595-
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`.
593+
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, `twoqueue` or `memcache`. (`twoqueue` represents a size limited LRU cache.)
594+
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory and twoqueue cache only.
595+
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`. For `twoqueue` sets configuration for the queue.
596596
- Redis: `redis://:[email protected]:6379/0?pool_size=100&idle_timeout=180s`
597597
- Memcache: `127.0.0.1:9090;127.0.0.1:9091`
598+
- TwoQueue LRU cache: `{"size":50000,"recent_ratio":0.25,"ghost_ratio":0.5}` or `50000` representing the maximum number of objects stored in the cache.
598599
- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching.
599600

600601
## Cache - LastCommitCache settings (`cache.last_commit`)

docs/content/doc/help/faq.en-us.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ If certain clone options aren't showing up (HTTP/S or SSH), the following option
8585
`DISABLE_SSH`: if set to true, there will be no SSH link
8686
`SSH_EXPOSE_ANONYMOUS`: if set to false, SSH links will be hidden for anonymous users
8787

88+
## File upload fails with: 413 Request Entity Too Large
89+
90+
This error occurs when the reverse proxy limits the file upload size.
91+
92+
See the [reverse proxy guide]({{< relref "doc/usage/reverse-proxies.en-us.md" >}}) for a solution with nginx.
93+
8894
## Custom Templates not loading or working incorrectly
8995

9096
Gitea's custom templates must be added to the correct location or Gitea will not find and use them.

docs/content/doc/usage/reverse-proxies.en-us.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ server {
120120
}
121121
```
122122

123+
## Resolving Error: 413 Request Entity Too Large
124+
125+
This error indicates nginx is configured to restrict the file upload size.
126+
127+
In your nginx config file containing your Gitea proxy directive, find the `location { ... }` block for Gitea and add the line
128+
`client_max_body_size 16M;` to set this limit to 16 megabytes or any other number of choice.
129+
130+
123131
## Apache HTTPD
124132

125133
If you want Apache HTTPD to serve your Gitea instance, you can add the following to your Apache HTTPD configuration (usually located at `/etc/apache2/httpd.conf` in Ubuntu):

modules/cache/cache_twoqueue.go

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cache
6+
7+
import (
8+
"strconv"
9+
"sync"
10+
"time"
11+
12+
mc "gitea.com/go-chi/cache"
13+
lru "github.com/hashicorp/golang-lru"
14+
jsoniter "github.com/json-iterator/go"
15+
)
16+
17+
// TwoQueueCache represents a LRU 2Q cache adapter implementation
18+
type TwoQueueCache struct {
19+
lock sync.Mutex
20+
cache *lru.TwoQueueCache
21+
interval int
22+
}
23+
24+
// TwoQueueCacheConfig describes the configuration for TwoQueueCache
25+
type TwoQueueCacheConfig struct {
26+
Size int `ini:"SIZE" json:"size"`
27+
RecentRatio float64 `ini:"RECENT_RATIO" json:"recent_ratio"`
28+
GhostRatio float64 `ini:"GHOST_RATIO" json:"ghost_ratio"`
29+
}
30+
31+
// MemoryItem represents a memory cache item.
32+
type MemoryItem struct {
33+
Val interface{}
34+
Created int64
35+
Timeout int64
36+
}
37+
38+
func (item *MemoryItem) hasExpired() bool {
39+
return item.Timeout > 0 &&
40+
(time.Now().Unix()-item.Created) >= item.Timeout
41+
}
42+
43+
var _ mc.Cache = &TwoQueueCache{}
44+
45+
// Put puts value into cache with key and expire time.
46+
func (c *TwoQueueCache) Put(key string, val interface{}, timeout int64) error {
47+
item := &MemoryItem{
48+
Val: val,
49+
Created: time.Now().Unix(),
50+
Timeout: timeout,
51+
}
52+
c.lock.Lock()
53+
defer c.lock.Unlock()
54+
c.cache.Add(key, item)
55+
return nil
56+
}
57+
58+
// Get gets cached value by given key.
59+
func (c *TwoQueueCache) Get(key string) interface{} {
60+
c.lock.Lock()
61+
defer c.lock.Unlock()
62+
cached, ok := c.cache.Get(key)
63+
if !ok {
64+
return nil
65+
}
66+
item, ok := cached.(*MemoryItem)
67+
68+
if !ok || item.hasExpired() {
69+
c.cache.Remove(key)
70+
return nil
71+
}
72+
73+
return item.Val
74+
}
75+
76+
// Delete deletes cached value by given key.
77+
func (c *TwoQueueCache) Delete(key string) error {
78+
c.lock.Lock()
79+
defer c.lock.Unlock()
80+
c.cache.Remove(key)
81+
return nil
82+
}
83+
84+
// Incr increases cached int-type value by given key as a counter.
85+
func (c *TwoQueueCache) Incr(key string) error {
86+
c.lock.Lock()
87+
defer c.lock.Unlock()
88+
cached, ok := c.cache.Get(key)
89+
if !ok {
90+
return nil
91+
}
92+
item, ok := cached.(*MemoryItem)
93+
94+
if !ok || item.hasExpired() {
95+
c.cache.Remove(key)
96+
return nil
97+
}
98+
99+
var err error
100+
item.Val, err = mc.Incr(item.Val)
101+
return err
102+
}
103+
104+
// Decr decreases cached int-type value by given key as a counter.
105+
func (c *TwoQueueCache) Decr(key string) error {
106+
c.lock.Lock()
107+
defer c.lock.Unlock()
108+
cached, ok := c.cache.Get(key)
109+
if !ok {
110+
return nil
111+
}
112+
item, ok := cached.(*MemoryItem)
113+
114+
if !ok || item.hasExpired() {
115+
c.cache.Remove(key)
116+
return nil
117+
}
118+
119+
var err error
120+
item.Val, err = mc.Decr(item.Val)
121+
return err
122+
}
123+
124+
// IsExist returns true if cached value exists.
125+
func (c *TwoQueueCache) IsExist(key string) bool {
126+
c.lock.Lock()
127+
defer c.lock.Unlock()
128+
cached, ok := c.cache.Peek(key)
129+
if !ok {
130+
return false
131+
}
132+
item, ok := cached.(*MemoryItem)
133+
if !ok || item.hasExpired() {
134+
c.cache.Remove(key)
135+
return false
136+
}
137+
138+
return true
139+
}
140+
141+
// Flush deletes all cached data.
142+
func (c *TwoQueueCache) Flush() error {
143+
c.lock.Lock()
144+
defer c.lock.Unlock()
145+
c.cache.Purge()
146+
return nil
147+
}
148+
149+
func (c *TwoQueueCache) checkAndInvalidate(key interface{}) {
150+
c.lock.Lock()
151+
defer c.lock.Unlock()
152+
cached, ok := c.cache.Peek(key)
153+
if !ok {
154+
return
155+
}
156+
item, ok := cached.(*MemoryItem)
157+
if !ok || item.hasExpired() {
158+
c.cache.Remove(item)
159+
}
160+
}
161+
162+
func (c *TwoQueueCache) startGC() {
163+
if c.interval < 0 {
164+
return
165+
}
166+
for _, key := range c.cache.Keys() {
167+
c.checkAndInvalidate(key)
168+
}
169+
time.AfterFunc(time.Duration(c.interval)*time.Second, c.startGC)
170+
}
171+
172+
// StartAndGC starts GC routine based on config string settings.
173+
func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
174+
var err error
175+
size := 50000
176+
if opts.AdapterConfig != "" {
177+
size, err = strconv.Atoi(opts.AdapterConfig)
178+
}
179+
if err != nil {
180+
json := jsoniter.ConfigCompatibleWithStandardLibrary
181+
if !json.Valid([]byte(opts.AdapterConfig)) {
182+
return err
183+
}
184+
185+
cfg := &TwoQueueCacheConfig{
186+
Size: 50000,
187+
RecentRatio: lru.Default2QRecentRatio,
188+
GhostRatio: lru.Default2QGhostEntries,
189+
}
190+
_ = json.Unmarshal([]byte(opts.AdapterConfig), cfg)
191+
c.cache, err = lru.New2QParams(cfg.Size, cfg.RecentRatio, cfg.GhostRatio)
192+
} else {
193+
c.cache, err = lru.New2Q(size)
194+
}
195+
c.interval = opts.Interval
196+
if c.interval > 0 {
197+
go c.startGC()
198+
}
199+
return err
200+
}
201+
202+
func init() {
203+
mc.Register("twoqueue", &TwoQueueCache{})
204+
}

modules/setting/cache.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ func newCacheService() {
5858
log.Fatal("Failed to map Cache settings: %v", err)
5959
}
6060

61-
CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
61+
CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache", "twoqueue"})
6262
switch CacheService.Adapter {
6363
case "memory":
6464
case "redis", "memcache":
6565
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
66+
case "twoqueue":
67+
CacheService.Conn = strings.TrimSpace(sec.Key("HOST").String())
68+
if CacheService.Conn == "" {
69+
CacheService.Conn = "50000"
70+
}
6671
case "": // disable cache
6772
CacheService.Enabled = false
6873
default:

options/locale/locale_de-DE.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ never=Niemals
100100
[error]
101101
occurred=Ein Fehler ist aufgetreten
102102
report_message=Wenn du dir sicher bist, dass dies ein Gitea-Fehler ist, suche bitte auf <a href="https://github.com/go-gitea/gitea/issues">GitHub</a> nach diesem Fehler und erstelle gegebenenfalls einen neuen Bugreport.
103+
missing_csrf=Fehlerhafte Anfrage: Kein CSRF Token verfügbar
104+
invalid_csrf=Fehlerhafte Anfrage: Ungültiger CSRF Token
103105

104106
[startpage]
105107
app_desc=Ein einfacher, selbst gehosteter Git-Service
@@ -1922,6 +1924,7 @@ settings.archive.success=Das Repo wurde erfolgreich archiviert.
19221924
settings.archive.error=Beim Versuch, das Repository zu archivieren, ist ein Fehler aufgetreten. Weitere Details finden sich im Log.
19231925
settings.archive.error_ismirror=Du kannst keinen Repo-Mirror archivieren.
19241926
settings.archive.branchsettings_unavailable=Branch-Einstellungen sind nicht verfügbar wenn das Repo archiviert ist.
1927+
settings.archive.tagsettings_unavailable=Tag Einstellungen sind nicht verfügbar, wenn das Repo archiviert wurde.
19251928
settings.unarchive.button=Archivieren rückgängig machen
19261929
settings.unarchive.header=Archivieren dieses Repos rückgängig machen
19271930
settings.unarchive.text=Durch das Aufheben der Archivierung kann das Repo wieder Commits und Pushes sowie neue Issues und Pull-Requests empfangen.

options/locale/locale_en-US.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ hi_user_x = Hi <b>%s</b>,
326326
327327
activate_account = Please activate your account
328328
activate_account.title = %s, please activate your account
329-
activate_account.test_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
330-
activate_account.test_2 = Please click the following link to activate your account within <b>%s</b>:
329+
activate_account.text_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
330+
activate_account.text_2 = Please click the following link to activate your account within <b>%s</b>:
331331
332332
activate_email = Verify your email address
333333
activate_email.title = %s, please verify your e-mail address

options/locale/locale_pt-PT.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,8 @@ issues.opened_by_fake=de %[2]s aberto %[1]s
11821182
issues.closed_by_fake=de %[2]s fechada %[1]s
11831183
issues.previous=Anterior
11841184
issues.next=Seguinte
1185-
issues.open_title=Abertas
1186-
issues.closed_title=Fechadas
1185+
issues.open_title=Aberta
1186+
issues.closed_title=Fechada
11871187
issues.num_comments=%d comentários
11881188
issues.commented_at=`comentado <a href="#%s">%s</a>`
11891189
issues.delete_comment_confirm=Tem a certeza que quer eliminar este comentário?
@@ -1414,11 +1414,11 @@ pulls.waiting_count_n=%d revisões pendentes
14141414
pulls.wrong_commit_id=ID do cometimento tem que ser um ID de cometimento no ramo de destino
14151415

14161416
pulls.no_merge_desc=A integração constante neste pedido não pode ser executada porque todas as opções de integração do repositório estão desabilitadas.
1417-
pulls.no_merge_helper=Habilite as opções de integração nas configurações do repositório ou faça manualmente a integração constante no pedido.
1417+
pulls.no_merge_helper=Habilite as opções de integração nas configurações do repositório ou faça a integração manualmente.
14181418
pulls.no_merge_wip=A integração constante neste pedido não pode ser executada porque está marcada como sendo trabalho em andamento.
14191419
pulls.no_merge_not_ready=A integração constante neste pedido não pode ser executada. Verifique o estado da revisão e as verificações de estado.
14201420
pulls.no_merge_access=Não tem autorização para executar a integração constante neste pedido.
1421-
pulls.merge_pull_request=Executar a integração constante no pedido
1421+
pulls.merge_pull_request=Executar a integração
14221422
pulls.rebase_merge_pull_request=Mudar a base e integrar
14231423
pulls.rebase_merge_commit_pull_request=Mudar a base e integrar (--no-ff)
14241424
pulls.squash_merge_pull_request=Comprimir e integrar

routers/init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func NewServices() {
5252
log.Fatal("repository init failed: %v", err)
5353
}
5454
mailer.NewContext()
55-
_ = cache.NewContext()
55+
if err := cache.NewContext(); err != nil {
56+
log.Fatal("Unable to start cache service: %v", err)
57+
}
5658
notification.NewContext()
5759
if err := archiver.Init(); err != nil {
5860
log.Fatal("archiver init failed: %v", err)

templates/mail/auth/activate.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
{{ $activate_url := printf "%suser/activate?code=%s" AppUrl .Code}}
99
<body>
10-
<p>{{.i18n.Tr "mail.activate_account.test_1" .DisplayName AppName | Str2html}}</p><br>
11-
<p>{{.i18n.Tr "mail.activate_account.test_2" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
12-
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>
10+
<p>{{.i18n.Tr "mail.activate_account.text_1" .DisplayName AppName | Str2html}}</p><br>
11+
<p>{{.i18n.Tr "mail.activate_account.text_2" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
12+
<p>{{.i18n.Tr "mail.link_not_working_do_paste"}}</p>
1313

1414
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1515
</body>

templates/mail/auth/activate_email.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body>
1010
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
1111
<p>{{.i18n.Tr "mail.activate_email.text" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
12-
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>
12+
<p>{{.i18n.Tr "mail.link_not_working_do_paste"}}</p>
1313

1414
<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
1515
</body>

0 commit comments

Comments
 (0)