Skip to content

Commit

Permalink
Merge branch 'go-gitea:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stanthetiger committed Jul 11, 2021
2 parents d3e844e + 2f725cb commit 3903fe8
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Dockerfile.rootless
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ COPY docker/rootless /
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini

USER 1000:1000 # git:git
#git:git
USER 1000:1000
ENV GITEA_WORK_DIR /var/lib/gitea
ENV GITEA_CUSTOM /var/lib/gitea/custom
ENV GITEA_TEMP /tmp/gitea
Expand Down
3 changes: 2 additions & 1 deletion custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ PATH =
;; if the cache enabled
;ENABLED = true
;;
;; Either "memory", "redis", or "memcache", default is "memory"
;; Either "memory", "redis", "memcache", or "twoqueue". default is "memory"
;ADAPTER = memory
;;
;; For "memory" only, GC interval in seconds, default is 60
Expand All @@ -1480,6 +1480,7 @@ PATH =
;; For "redis" and "memcache", connection host address
;; redis: network=tcp,addr=:6379,password=macaron,db=0,pool_size=100,idle_timeout=180
;; memcache: `127.0.0.1:11211`
;; twoqueue: `{"size":50000,"recent_ratio":0.25,"ghost_ratio":0.5}` or `50000`
;HOST =
;;
;; Time to keep items in cache if not used, default is 16 hours.
Expand Down
7 changes: 4 additions & 3 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,12 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
## Cache (`cache`)

- `ENABLED`: **true**: Enable the cache.
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, or `memcache`.
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory cache only.
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`.
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, `twoqueue` or `memcache`. (`twoqueue` represents a size limited LRU cache.)
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory and twoqueue cache only.
- `HOST`: **\<empty\>**: Connection string for `redis` and `memcache`. For `twoqueue` sets configuration for the queue.
- Redis: `redis://:macaron@127.0.0.1:6379/0?pool_size=100&idle_timeout=180s`
- Memcache: `127.0.0.1:9090;127.0.0.1:9091`
- 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.
- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to 0 disables caching.

## Cache - LastCommitCache settings (`cache.last_commit`)
Expand Down
6 changes: 6 additions & 0 deletions docs/content/doc/help/faq.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ If certain clone options aren't showing up (HTTP/S or SSH), the following option
`DISABLE_SSH`: if set to true, there will be no SSH link
`SSH_EXPOSE_ANONYMOUS`: if set to false, SSH links will be hidden for anonymous users

## File upload fails with: 413 Request Entity Too Large

This error occurs when the reverse proxy limits the file upload size.

See the [reverse proxy guide]({{< relref "doc/usage/reverse-proxies.en-us.md" >}}) for a solution with nginx.

## Custom Templates not loading or working incorrectly

Gitea's custom templates must be added to the correct location or Gitea will not find and use them.
Expand Down
8 changes: 8 additions & 0 deletions docs/content/doc/usage/reverse-proxies.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ server {
}
```

## Resolving Error: 413 Request Entity Too Large

This error indicates nginx is configured to restrict the file upload size.

In your nginx config file containing your Gitea proxy directive, find the `location { ... }` block for Gitea and add the line
`client_max_body_size 16M;` to set this limit to 16 megabytes or any other number of choice.


## Apache HTTPD

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):
Expand Down
204 changes: 204 additions & 0 deletions modules/cache/cache_twoqueue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// Copyright 2021 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 cache

import (
"strconv"
"sync"
"time"

mc "gitea.com/go-chi/cache"
lru "github.com/hashicorp/golang-lru"
jsoniter "github.com/json-iterator/go"
)

// TwoQueueCache represents a LRU 2Q cache adapter implementation
type TwoQueueCache struct {
lock sync.Mutex
cache *lru.TwoQueueCache
interval int
}

// TwoQueueCacheConfig describes the configuration for TwoQueueCache
type TwoQueueCacheConfig struct {
Size int `ini:"SIZE" json:"size"`
RecentRatio float64 `ini:"RECENT_RATIO" json:"recent_ratio"`
GhostRatio float64 `ini:"GHOST_RATIO" json:"ghost_ratio"`
}

// MemoryItem represents a memory cache item.
type MemoryItem struct {
Val interface{}
Created int64
Timeout int64
}

func (item *MemoryItem) hasExpired() bool {
return item.Timeout > 0 &&
(time.Now().Unix()-item.Created) >= item.Timeout
}

var _ mc.Cache = &TwoQueueCache{}

// Put puts value into cache with key and expire time.
func (c *TwoQueueCache) Put(key string, val interface{}, timeout int64) error {
item := &MemoryItem{
Val: val,
Created: time.Now().Unix(),
Timeout: timeout,
}
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Add(key, item)
return nil
}

// Get gets cached value by given key.
func (c *TwoQueueCache) Get(key string) interface{} {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Get(key)
if !ok {
return nil
}
item, ok := cached.(*MemoryItem)

if !ok || item.hasExpired() {
c.cache.Remove(key)
return nil
}

return item.Val
}

// Delete deletes cached value by given key.
func (c *TwoQueueCache) Delete(key string) error {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Remove(key)
return nil
}

// Incr increases cached int-type value by given key as a counter.
func (c *TwoQueueCache) Incr(key string) error {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Get(key)
if !ok {
return nil
}
item, ok := cached.(*MemoryItem)

if !ok || item.hasExpired() {
c.cache.Remove(key)
return nil
}

var err error
item.Val, err = mc.Incr(item.Val)
return err
}

// Decr decreases cached int-type value by given key as a counter.
func (c *TwoQueueCache) Decr(key string) error {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Get(key)
if !ok {
return nil
}
item, ok := cached.(*MemoryItem)

if !ok || item.hasExpired() {
c.cache.Remove(key)
return nil
}

var err error
item.Val, err = mc.Decr(item.Val)
return err
}

// IsExist returns true if cached value exists.
func (c *TwoQueueCache) IsExist(key string) bool {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Peek(key)
if !ok {
return false
}
item, ok := cached.(*MemoryItem)
if !ok || item.hasExpired() {
c.cache.Remove(key)
return false
}

return true
}

// Flush deletes all cached data.
func (c *TwoQueueCache) Flush() error {
c.lock.Lock()
defer c.lock.Unlock()
c.cache.Purge()
return nil
}

func (c *TwoQueueCache) checkAndInvalidate(key interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Peek(key)
if !ok {
return
}
item, ok := cached.(*MemoryItem)
if !ok || item.hasExpired() {
c.cache.Remove(item)
}
}

func (c *TwoQueueCache) startGC() {
if c.interval < 0 {
return
}
for _, key := range c.cache.Keys() {
c.checkAndInvalidate(key)
}
time.AfterFunc(time.Duration(c.interval)*time.Second, c.startGC)
}

// StartAndGC starts GC routine based on config string settings.
func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
var err error
size := 50000
if opts.AdapterConfig != "" {
size, err = strconv.Atoi(opts.AdapterConfig)
}
if err != nil {
json := jsoniter.ConfigCompatibleWithStandardLibrary
if !json.Valid([]byte(opts.AdapterConfig)) {
return err
}

cfg := &TwoQueueCacheConfig{
Size: 50000,
RecentRatio: lru.Default2QRecentRatio,
GhostRatio: lru.Default2QGhostEntries,
}
_ = json.Unmarshal([]byte(opts.AdapterConfig), cfg)
c.cache, err = lru.New2QParams(cfg.Size, cfg.RecentRatio, cfg.GhostRatio)
} else {
c.cache, err = lru.New2Q(size)
}
c.interval = opts.Interval
if c.interval > 0 {
go c.startGC()
}
return err
}

func init() {
mc.Register("twoqueue", &TwoQueueCache{})
}
7 changes: 6 additions & 1 deletion modules/setting/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ func newCacheService() {
log.Fatal("Failed to map Cache settings: %v", err)
}

CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache"})
CacheService.Adapter = sec.Key("ADAPTER").In("memory", []string{"memory", "redis", "memcache", "twoqueue"})
switch CacheService.Adapter {
case "memory":
case "redis", "memcache":
CacheService.Conn = strings.Trim(sec.Key("HOST").String(), "\" ")
case "twoqueue":
CacheService.Conn = strings.TrimSpace(sec.Key("HOST").String())
if CacheService.Conn == "" {
CacheService.Conn = "50000"
}
case "": // disable cache
CacheService.Enabled = false
default:
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ never=Niemals
[error]
occurred=Ein Fehler ist aufgetreten
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.
missing_csrf=Fehlerhafte Anfrage: Kein CSRF Token verfügbar
invalid_csrf=Fehlerhafte Anfrage: Ungültiger CSRF Token

[startpage]
app_desc=Ein einfacher, selbst gehosteter Git-Service
Expand Down Expand Up @@ -1922,6 +1924,7 @@ settings.archive.success=Das Repo wurde erfolgreich archiviert.
settings.archive.error=Beim Versuch, das Repository zu archivieren, ist ein Fehler aufgetreten. Weitere Details finden sich im Log.
settings.archive.error_ismirror=Du kannst keinen Repo-Mirror archivieren.
settings.archive.branchsettings_unavailable=Branch-Einstellungen sind nicht verfügbar wenn das Repo archiviert ist.
settings.archive.tagsettings_unavailable=Tag Einstellungen sind nicht verfügbar, wenn das Repo archiviert wurde.
settings.unarchive.button=Archivieren rückgängig machen
settings.unarchive.header=Archivieren dieses Repos rückgängig machen
settings.unarchive.text=Durch das Aufheben der Archivierung kann das Repo wieder Commits und Pushes sowie neue Issues und Pull-Requests empfangen.
Expand Down
4 changes: 2 additions & 2 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ hi_user_x = Hi <b>%s</b>,
activate_account = Please activate your account
activate_account.title = %s, please activate your account
activate_account.test_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
activate_account.test_2 = Please click the following link to activate your account within <b>%s</b>:
activate_account.text_1 = Hi <b>%[1]s</b>, thanks for registering at %[2]s!
activate_account.text_2 = Please click the following link to activate your account within <b>%s</b>:
activate_email = Verify your email address
activate_email.title = %s, please verify your e-mail address
Expand Down
8 changes: 4 additions & 4 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,8 @@ issues.opened_by_fake=de %[2]s aberto %[1]s
issues.closed_by_fake=de %[2]s fechada %[1]s
issues.previous=Anterior
issues.next=Seguinte
issues.open_title=Abertas
issues.closed_title=Fechadas
issues.open_title=Aberta
issues.closed_title=Fechada
issues.num_comments=%d comentários
issues.commented_at=`comentado <a href="#%s">%s</a>`
issues.delete_comment_confirm=Tem a certeza que quer eliminar este comentário?
Expand Down Expand Up @@ -1414,11 +1414,11 @@ pulls.waiting_count_n=%d revisões pendentes
pulls.wrong_commit_id=ID do cometimento tem que ser um ID de cometimento no ramo de destino

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.
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.
pulls.no_merge_helper=Habilite as opções de integração nas configurações do repositório ou faça a integração manualmente.
pulls.no_merge_wip=A integração constante neste pedido não pode ser executada porque está marcada como sendo trabalho em andamento.
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.
pulls.no_merge_access=Não tem autorização para executar a integração constante neste pedido.
pulls.merge_pull_request=Executar a integração constante no pedido
pulls.merge_pull_request=Executar a integração
pulls.rebase_merge_pull_request=Mudar a base e integrar
pulls.rebase_merge_commit_pull_request=Mudar a base e integrar (--no-ff)
pulls.squash_merge_pull_request=Comprimir e integrar
Expand Down
4 changes: 3 additions & 1 deletion routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func NewServices() {
log.Fatal("repository init failed: %v", err)
}
mailer.NewContext()
_ = cache.NewContext()
if err := cache.NewContext(); err != nil {
log.Fatal("Unable to start cache service: %v", err)
}
notification.NewContext()
if err := archiver.Init(); err != nil {
log.Fatal("archiver init failed: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions templates/mail/auth/activate.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

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

<p>© <a target="_blank" rel="noopener noreferrer" href="{{AppUrl}}">{{AppName}}</a></p>
</body>
Expand Down
2 changes: 1 addition & 1 deletion templates/mail/auth/activate_email.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<p>{{.i18n.Tr "mail.hi_user_x" .DisplayName | Str2html}}</p><br>
<p>{{.i18n.Tr "mail.activate_email.text" .ActiveCodeLives | Str2html}}</p><p><a href="{{$activate_url}}">{{$activate_url}}</a></p><br>
<p>{{.i18n.Tr "mail.link_not_working_do_paste" .DisplayName AppName | Str2html}}</p>
<p>{{.i18n.Tr "mail.link_not_working_do_paste"}}</p>

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

0 comments on commit 3903fe8

Please sign in to comment.