mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Fix system config cache expiration timing (#28072)
To avoid unnecessary database access, the `cacheTime` should always be set if the revision has been checked. Fix #28057
This commit is contained in:
		@@ -115,24 +115,26 @@ func (d *dbConfigCachedGetter) GetValue(ctx context.Context, key string) (v stri
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int {
 | 
					func (d *dbConfigCachedGetter) GetRevision(ctx context.Context) int {
 | 
				
			||||||
	d.mu.RLock()
 | 
						d.mu.RLock()
 | 
				
			||||||
	defer d.mu.RUnlock()
 | 
						cachedDuration := time.Since(d.cacheTime)
 | 
				
			||||||
	if time.Since(d.cacheTime) < time.Second {
 | 
						cachedRevision := d.revision
 | 
				
			||||||
		return d.revision
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if GetRevision(ctx) != d.revision {
 | 
					 | 
				
			||||||
	d.mu.RUnlock()
 | 
						d.mu.RUnlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if cachedDuration < time.Second {
 | 
				
			||||||
 | 
							return cachedRevision
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d.mu.Lock()
 | 
						d.mu.Lock()
 | 
				
			||||||
 | 
						defer d.mu.Unlock()
 | 
				
			||||||
 | 
						if GetRevision(ctx) != d.revision {
 | 
				
			||||||
		rev, set, err := GetAllSettings(ctx)
 | 
							rev, set, err := GetAllSettings(ctx)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Error("Unable to get all settings: %v", err)
 | 
								log.Error("Unable to get all settings: %v", err)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			d.cacheTime = time.Now()
 | 
					 | 
				
			||||||
			d.revision = rev
 | 
								d.revision = rev
 | 
				
			||||||
			d.settings = set
 | 
								d.settings = set
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		d.mu.Unlock()
 | 
					 | 
				
			||||||
		d.mu.RLock()
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						d.cacheTime = time.Now()
 | 
				
			||||||
	return d.revision
 | 
						return d.revision
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user