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
501e8f1e
Commit
501e8f1e
authored
Jan 22, 2026
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: implement read-write lock for owner cache
parent
edcddf3c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
1 deletion
+20
-1
instance_service.go
server/router/api/v1/instance_service.go
+20
-1
No files found.
server/router/api/v1/instance_service.go
View file @
501e8f1e
...
@@ -3,6 +3,7 @@ package v1
...
@@ -3,6 +3,7 @@ package v1
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"sync"
"github.com/pkg/errors"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
...
@@ -269,9 +270,25 @@ func convertInstanceMemoRelatedSettingToStore(setting *v1pb.InstanceSetting_Memo
...
@@ -269,9 +270,25 @@ func convertInstanceMemoRelatedSettingToStore(setting *v1pb.InstanceSetting_Memo
}
}
}
}
var
ownerCache
*
v1pb
.
User
var
(
ownerCache
*
v1pb
.
User
ownerCacheMutex
sync
.
RWMutex
)
func
(
s
*
APIV1Service
)
GetInstanceOwner
(
ctx
context
.
Context
)
(
*
v1pb
.
User
,
error
)
{
func
(
s
*
APIV1Service
)
GetInstanceOwner
(
ctx
context
.
Context
)
(
*
v1pb
.
User
,
error
)
{
// Try read lock first for cache hit
ownerCacheMutex
.
RLock
()
if
ownerCache
!=
nil
{
defer
ownerCacheMutex
.
RUnlock
()
return
ownerCache
,
nil
}
ownerCacheMutex
.
RUnlock
()
// Upgrade to write lock to populate cache
ownerCacheMutex
.
Lock
()
defer
ownerCacheMutex
.
Unlock
()
// Double-check after acquiring write lock
if
ownerCache
!=
nil
{
if
ownerCache
!=
nil
{
return
ownerCache
,
nil
return
ownerCache
,
nil
}
}
...
@@ -294,5 +311,7 @@ func (s *APIV1Service) GetInstanceOwner(ctx context.Context) (*v1pb.User, error)
...
@@ -294,5 +311,7 @@ func (s *APIV1Service) GetInstanceOwner(ctx context.Context) (*v1pb.User, error)
// ClearInstanceOwnerCache clears the cached instance owner.
// ClearInstanceOwnerCache clears the cached instance owner.
// This should be called when an admin user is created or when the owner changes.
// This should be called when an admin user is created or when the owner changes.
func
(
*
APIV1Service
)
ClearInstanceOwnerCache
()
{
func
(
*
APIV1Service
)
ClearInstanceOwnerCache
()
{
ownerCacheMutex
.
Lock
()
defer
ownerCacheMutex
.
Unlock
()
ownerCache
=
nil
ownerCache
=
nil
}
}
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