Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
ef6f80d9
Commit
ef6f80d9
authored
May 27, 2025
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix linter
parent
81ae4251
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
24 deletions
+17
-24
profiler.go
server/profiler/profiler.go
+1
-2
rss.go
server/router/rss/rss.go
+3
-3
runner.go
server/runner/memopayload/runner.go
+0
-4
runner.go
server/runner/s3presign/runner.go
+0
-4
server.go
server/server.go
+0
-3
cache.go
store/cache/cache.go
+13
-8
No files found.
server/profiler/profiler.go
View file @
ef6f80d9
...
...
@@ -25,7 +25,7 @@ func NewProfiler() *Profiler {
}
// RegisterRoutes adds profiling endpoints to the Echo server.
func
(
p
*
Profiler
)
RegisterRoutes
(
e
*
echo
.
Echo
)
{
func
(
*
Profiler
)
RegisterRoutes
(
e
*
echo
.
Echo
)
{
// Register pprof handlers
g
:=
e
.
Group
(
"/debug/pprof"
)
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.
if
m
.
HeapAlloc
>
500
*
1024
*
1024
{
// 500 MB threshold
slog
.
Info
(
"forcing garbage collection due to high memory usage"
)
runtime
.
GC
()
}
case
<-
ctx
.
Done
()
:
return
...
...
server/router/rss/rss.go
View file @
ef6f80d9
...
...
@@ -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
)
{
rssHeading
,
err
:=
getRSSHeading
(
s
.
Store
,
ctx
)
rssHeading
,
err
:=
getRSSHeading
(
ctx
,
s
.
Store
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -160,8 +160,8 @@ func getRSSItemDescription(content string) (string, error) {
return
result
,
nil
}
func
getRSSHeading
(
store
*
store
.
Store
,
ctx
context
.
Context
)
(
RSSHeading
,
error
)
{
settings
,
err
:=
store
.
GetWorkspaceGeneralSetting
(
ctx
)
func
getRSSHeading
(
ctx
context
.
Context
,
stores
*
store
.
Store
)
(
RSSHeading
,
error
)
{
settings
,
err
:=
store
s
.
GetWorkspaceGeneralSetting
(
ctx
)
if
err
!=
nil
{
return
RSSHeading
{},
err
}
...
...
server/runner/memopayload/runner.go
View file @
ef6f80d9
...
...
@@ -3,7 +3,6 @@ package memopayload
import
(
"context"
"log/slog"
"runtime"
"slices"
"github.com/pkg/errors"
...
...
@@ -70,9 +69,6 @@ func (r *Runner) RunOnce(ctx context.Context) {
// Move to next batch
offset
+=
len
(
memos
)
// Force garbage collection between batches to prevent memory accumulation
runtime
.
GC
()
}
}
...
...
server/runner/s3presign/runner.go
View file @
ef6f80d9
...
...
@@ -3,7 +3,6 @@ package s3presign
import
(
"context"
"log/slog"
"runtime"
"time"
"google.golang.org/protobuf/types/known/timestamppb"
...
...
@@ -131,8 +130,5 @@ func (r *Runner) CheckAndPresign(ctx context.Context) {
// Move to next batch
offset
+=
len
(
resources
)
// Prevent memory accumulation between batches
runtime
.
GC
()
}
}
server/server.go
View file @
ef6f80d9
...
...
@@ -163,9 +163,6 @@ func (s *Server) Shutdown(ctx context.Context) {
// Stop the profiler
if
s
.
profiler
!=
nil
{
slog
.
Info
(
"stopping profiler"
)
// Force one last garbage collection to clean up remaining objects
runtime
.
GC
()
// Log final memory stats
var
m
runtime
.
MemStats
runtime
.
ReadMemStats
(
&
m
)
...
...
store/cache/cache.go
View file @
ef6f80d9
...
...
@@ -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.
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).
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.
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
)
if
!
ok
{
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
)
{
c
.
data
.
Delete
(
key
)
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.
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
{
atomic
.
AddInt64
(
&
c
.
itemCount
,
-
1
)
if
c
.
config
.
OnEviction
!=
nil
{
itm
:=
value
.
(
item
)
itm
,
_
:=
value
.
(
item
)
c
.
config
.
OnEviction
(
key
,
itm
.
value
)
}
}
}
// 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
{
c
.
data
.
Range
(
func
(
key
,
value
any
)
bool
{
itm
:=
value
.
(
item
)
itm
,
_
:=
value
.
(
item
)
c
.
config
.
OnEviction
(
key
.
(
string
),
itm
.
value
)
return
true
})
...
...
@@ -209,7 +214,7 @@ func (c *Cache) cleanup() {
count
:=
0
c
.
data
.
Range
(
func
(
key
,
value
any
)
bool
{
itm
:=
value
.
(
item
)
itm
,
_
:=
value
.
(
item
)
if
time
.
Now
()
.
After
(
itm
.
expiration
)
{
c
.
data
.
Delete
(
key
)
count
++
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment