mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: fix linter
This commit is contained in:
@ -25,7 +25,7 @@ func NewProfiler() *Profiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterRoutes adds profiling endpoints to the Echo server.
|
// RegisterRoutes adds profiling endpoints to the Echo server.
|
||||||
func (p *Profiler) RegisterRoutes(e *echo.Echo) {
|
func (*Profiler) RegisterRoutes(e *echo.Echo) {
|
||||||
// Register pprof handlers
|
// Register pprof handlers
|
||||||
g := e.Group("/debug/pprof")
|
g := e.Group("/debug/pprof")
|
||||||
g.GET("", echo.WrapHandler(http.HandlerFunc(pprof.Index)))
|
g.GET("", echo.WrapHandler(http.HandlerFunc(pprof.Index)))
|
||||||
@ -97,7 +97,6 @@ func (p *Profiler) StartMemoryMonitor(ctx context.Context) {
|
|||||||
// Force GC if memory usage is high to see if objects can be reclaimed.
|
// Force GC if memory usage is high to see if objects can be reclaimed.
|
||||||
if m.HeapAlloc > 500*1024*1024 { // 500 MB threshold
|
if m.HeapAlloc > 500*1024*1024 { // 500 MB threshold
|
||||||
slog.Info("forcing garbage collection due to high memory usage")
|
slog.Info("forcing garbage collection due to high memory usage")
|
||||||
runtime.GC()
|
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -98,7 +98,7 @@ func (s *RSSService) GetUserRSS(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*store.Memo, baseURL string) (string, error) {
|
func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*store.Memo, baseURL string) (string, error) {
|
||||||
rssHeading, err := getRSSHeading(s.Store, ctx)
|
rssHeading, err := getRSSHeading(ctx, s.Store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -160,8 +160,8 @@ func getRSSItemDescription(content string) (string, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRSSHeading(store *store.Store, ctx context.Context) (RSSHeading, error) {
|
func getRSSHeading(ctx context.Context, stores *store.Store) (RSSHeading, error) {
|
||||||
settings, err := store.GetWorkspaceGeneralSetting(ctx)
|
settings, err := stores.GetWorkspaceGeneralSetting(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RSSHeading{}, err
|
return RSSHeading{}, err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package memopayload
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"runtime"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -70,9 +69,6 @@ func (r *Runner) RunOnce(ctx context.Context) {
|
|||||||
|
|
||||||
// Move to next batch
|
// Move to next batch
|
||||||
offset += len(memos)
|
offset += len(memos)
|
||||||
|
|
||||||
// Force garbage collection between batches to prevent memory accumulation
|
|
||||||
runtime.GC()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package s3presign
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
@ -131,8 +130,5 @@ func (r *Runner) CheckAndPresign(ctx context.Context) {
|
|||||||
|
|
||||||
// Move to next batch
|
// Move to next batch
|
||||||
offset += len(resources)
|
offset += len(resources)
|
||||||
|
|
||||||
// Prevent memory accumulation between batches
|
|
||||||
runtime.GC()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,9 +163,6 @@ func (s *Server) Shutdown(ctx context.Context) {
|
|||||||
// Stop the profiler
|
// Stop the profiler
|
||||||
if s.profiler != nil {
|
if s.profiler != nil {
|
||||||
slog.Info("stopping profiler")
|
slog.Info("stopping profiler")
|
||||||
// Force one last garbage collection to clean up remaining objects
|
|
||||||
runtime.GC()
|
|
||||||
|
|
||||||
// Log final memory stats
|
// Log final memory stats
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
|
21
store/cache/cache.go
vendored
21
store/cache/cache.go
vendored
@ -95,7 +95,7 @@ func (c *Cache) Set(ctx context.Context, key string, value any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetWithTTL adds a value to the cache with a custom TTL.
|
// SetWithTTL adds a value to the cache with a custom TTL.
|
||||||
func (c *Cache) SetWithTTL(ctx context.Context, key string, value any, ttl time.Duration) {
|
func (c *Cache) SetWithTTL(_ context.Context, key string, value any, ttl time.Duration) {
|
||||||
// Estimate size of the item (very rough approximation).
|
// Estimate size of the item (very rough approximation).
|
||||||
size := estimateSize(value)
|
size := estimateSize(value)
|
||||||
|
|
||||||
@ -120,13 +120,18 @@ func (c *Cache) SetWithTTL(ctx context.Context, key string, value any, ttl time.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get retrieves a value from the cache.
|
// Get retrieves a value from the cache.
|
||||||
func (c *Cache) Get(ctx context.Context, key string) (any, bool) {
|
func (c *Cache) Get(_ context.Context, key string) (any, bool) {
|
||||||
value, ok := c.data.Load(key)
|
value, ok := c.data.Load(key)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
itm := value.(item)
|
itm, ok := value.(item)
|
||||||
|
if !ok {
|
||||||
|
// If the value is not of type item, it means it was corrupted or not set correctly.
|
||||||
|
c.data.Delete(key)
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
if time.Now().After(itm.expiration) {
|
if time.Now().After(itm.expiration) {
|
||||||
c.data.Delete(key)
|
c.data.Delete(key)
|
||||||
atomic.AddInt64(&c.itemCount, -1)
|
atomic.AddInt64(&c.itemCount, -1)
|
||||||
@ -142,22 +147,22 @@ func (c *Cache) Get(ctx context.Context, key string) (any, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete removes a value from the cache.
|
// Delete removes a value from the cache.
|
||||||
func (c *Cache) Delete(ctx context.Context, key string) {
|
func (c *Cache) Delete(_ context.Context, key string) {
|
||||||
if value, loaded := c.data.LoadAndDelete(key); loaded {
|
if value, loaded := c.data.LoadAndDelete(key); loaded {
|
||||||
atomic.AddInt64(&c.itemCount, -1)
|
atomic.AddInt64(&c.itemCount, -1)
|
||||||
|
|
||||||
if c.config.OnEviction != nil {
|
if c.config.OnEviction != nil {
|
||||||
itm := value.(item)
|
itm, _ := value.(item)
|
||||||
c.config.OnEviction(key, itm.value)
|
c.config.OnEviction(key, itm.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear removes all values from the cache.
|
// Clear removes all values from the cache.
|
||||||
func (c *Cache) Clear(ctx context.Context) {
|
func (c *Cache) Clear(_ context.Context) {
|
||||||
if c.config.OnEviction != nil {
|
if c.config.OnEviction != nil {
|
||||||
c.data.Range(func(key, value any) bool {
|
c.data.Range(func(key, value any) bool {
|
||||||
itm := value.(item)
|
itm, _ := value.(item)
|
||||||
c.config.OnEviction(key.(string), itm.value)
|
c.config.OnEviction(key.(string), itm.value)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@ -209,7 +214,7 @@ func (c *Cache) cleanup() {
|
|||||||
count := 0
|
count := 0
|
||||||
|
|
||||||
c.data.Range(func(key, value any) bool {
|
c.data.Range(func(key, value any) bool {
|
||||||
itm := value.(item)
|
itm, _ := value.(item)
|
||||||
if time.Now().After(itm.expiration) {
|
if time.Now().After(itm.expiration) {
|
||||||
c.data.Delete(key)
|
c.data.Delete(key)
|
||||||
count++
|
count++
|
||||||
|
Reference in New Issue
Block a user