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
4603f414
Unverified
Commit
4603f414
authored
Apr 27, 2023
by
boojack
Committed by
GitHub
Apr 27, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add system setting cache (#1609)
parent
884dca20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
store.go
store/store.go
+6
-5
system_setting.go
store/system_setting.go
+9
-3
No files found.
store/store.go
View file @
4603f414
...
...
@@ -13,11 +13,12 @@ type Store struct {
db
*
sql
.
DB
profile
*
profile
.
Profile
userCache
sync
.
Map
// map[int]*userRaw
userSettingCache
sync
.
Map
// map[string]*userSettingRaw
memoCache
sync
.
Map
// map[int]*memoRaw
shortcutCache
sync
.
Map
// map[int]*shortcutRaw
idpCache
sync
.
Map
// map[int]*identityProviderMessage
systemSettingCache
sync
.
Map
// map[string]*systemSettingRaw
userCache
sync
.
Map
// map[int]*userRaw
userSettingCache
sync
.
Map
// map[string]*userSettingRaw
memoCache
sync
.
Map
// map[int]*memoRaw
shortcutCache
sync
.
Map
// map[int]*shortcutRaw
idpCache
sync
.
Map
// map[int]*identityProviderMessage
}
// New creates a new instance of Store.
...
...
store/system_setting.go
View file @
4603f414
...
...
@@ -41,7 +41,7 @@ func (s *Store) UpsertSystemSetting(ctx context.Context, upsert *api.SystemSetti
}
systemSetting
:=
systemSettingRaw
.
toSystemSetting
()
s
.
systemSettingCache
.
Store
(
systemSettingRaw
.
Name
,
systemSettingRaw
)
return
systemSetting
,
nil
}
...
...
@@ -63,13 +63,17 @@ func (s *Store) FindSystemSettingList(ctx context.Context, find *api.SystemSetti
list
:=
[]
*
api
.
SystemSetting
{}
for
_
,
raw
:=
range
systemSettingRawList
{
s
.
systemSettingCache
.
Store
(
raw
.
Name
,
raw
)
list
=
append
(
list
,
raw
.
toSystemSetting
())
}
return
list
,
nil
}
func
(
s
*
Store
)
FindSystemSetting
(
ctx
context
.
Context
,
find
*
api
.
SystemSettingFind
)
(
*
api
.
SystemSetting
,
error
)
{
if
systemSetting
,
ok
:=
s
.
systemSettingCache
.
Load
(
find
.
Name
);
ok
{
systemSettingRaw
:=
systemSetting
.
(
*
systemSettingRaw
)
return
systemSettingRaw
.
toSystemSetting
(),
nil
}
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
return
nil
,
FormatError
(
err
)
...
...
@@ -85,7 +89,9 @@ func (s *Store) FindSystemSetting(ctx context.Context, find *api.SystemSettingFi
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"not found"
)}
}
return
systemSettingRawList
[
0
]
.
toSystemSetting
(),
nil
systemSettingRaw
:=
systemSettingRawList
[
0
]
s
.
systemSettingCache
.
Store
(
systemSettingRaw
.
Name
,
systemSettingRaw
)
return
systemSettingRaw
.
toSystemSetting
(),
nil
}
func
upsertSystemSetting
(
ctx
context
.
Context
,
tx
*
sql
.
Tx
,
upsert
*
api
.
SystemSettingUpsert
)
(
*
systemSettingRaw
,
error
)
{
...
...
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