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
9f8c0ce5
Commit
9f8c0ce5
authored
Oct 01, 2022
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: raw data cache
parent
c7cf35c7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
66 deletions
+66
-66
memo.go
store/memo.go
+16
-11
memo_resource.go
store/memo_resource.go
+0
-25
resource.go
store/resource.go
+23
-8
shortcut.go
store/shortcut.go
+13
-11
user.go
store/user.go
+14
-11
No files found.
store/memo.go
View file @
9f8c0ce5
...
...
@@ -83,12 +83,12 @@ func (s *Store) CreateMemo(ctx context.Context, create *api.MemoCreate) (*api.Me
return
nil
,
FormatError
(
err
)
}
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memo
.
ID
,
memo
);
err
!=
nil
{
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -111,12 +111,12 @@ func (s *Store) PatchMemo(ctx context.Context, patch *api.MemoPatch) (*api.Memo,
return
nil
,
FormatError
(
err
)
}
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memo
.
ID
,
memo
);
err
!=
nil
{
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -150,12 +150,16 @@ func (s *Store) FindMemoList(ctx context.Context, find *api.MemoFind) ([]*api.Me
func
(
s
*
Store
)
FindMemo
(
ctx
context
.
Context
,
find
*
api
.
MemoFind
)
(
*
api
.
Memo
,
error
)
{
if
find
.
ID
!=
nil
{
memo
:=
&
api
.
Memo
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
MemoCache
,
*
find
.
ID
,
memo
)
memo
Raw
:=
&
memoRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
MemoCache
,
*
find
.
ID
,
memo
Raw
)
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
return
nil
,
err
}
return
memo
,
nil
}
}
...
...
@@ -175,12 +179,13 @@ func (s *Store) FindMemo(ctx context.Context, find *api.MemoFind) (*api.Memo, er
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"not found"
)}
}
memo
,
err
:=
s
.
composeMemo
(
ctx
,
list
[
0
])
if
err
!=
nil
{
memo
Raw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memoRaw
.
ID
,
memoRaw
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
MemoCache
,
memo
.
ID
,
memo
);
err
!=
nil
{
memo
,
err
:=
s
.
composeMemo
(
ctx
,
memoRaw
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
store/memo_resource.go
View file @
9f8c0ce5
...
...
@@ -28,31 +28,6 @@ func (raw *memoResourceRaw) toMemoResource() *api.MemoResource {
}
}
func
(
s
*
Store
)
ComposeMemoResourceList
(
ctx
context
.
Context
,
memo
*
api
.
Memo
)
error
{
memoResourceList
,
err
:=
s
.
FindMemoResourceList
(
ctx
,
&
api
.
MemoResourceFind
{
MemoID
:
&
memo
.
ID
,
})
if
err
!=
nil
{
return
err
}
resourceList
:=
[]
*
api
.
Resource
{}
for
_
,
memoResource
:=
range
memoResourceList
{
resource
,
err
:=
s
.
FindResource
(
ctx
,
&
api
.
ResourceFind
{
ID
:
&
memoResource
.
ResourceID
,
})
if
err
!=
nil
{
return
err
}
resourceList
=
append
(
resourceList
,
resource
)
}
memo
.
ResourceList
=
resourceList
return
nil
}
func
(
s
*
Store
)
FindMemoResourceList
(
ctx
context
.
Context
,
find
*
api
.
MemoResourceFind
)
([]
*
api
.
MemoResource
,
error
)
{
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
...
...
store/resource.go
View file @
9f8c0ce5
...
...
@@ -44,6 +44,19 @@ func (raw *resourceRaw) toResource() *api.Resource {
}
}
func
(
s
*
Store
)
ComposeMemoResourceList
(
ctx
context
.
Context
,
memo
*
api
.
Memo
)
error
{
resourceList
,
err
:=
s
.
FindResourceList
(
ctx
,
&
api
.
ResourceFind
{
MemoID
:
&
memo
.
ID
,
})
if
err
!=
nil
{
return
err
}
memo
.
ResourceList
=
resourceList
return
nil
}
func
(
s
*
Store
)
CreateResource
(
ctx
context
.
Context
,
create
*
api
.
ResourceCreate
)
(
*
api
.
Resource
,
error
)
{
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
...
...
@@ -60,12 +73,12 @@ func (s *Store) CreateResource(ctx context.Context, create *api.ResourceCreate)
return
nil
,
FormatError
(
err
)
}
resource
:=
resourceRaw
.
toResource
()
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resource
.
ID
,
resource
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resourceRaw
.
ID
,
resourceRaw
);
err
!=
nil
{
return
nil
,
err
}
resource
:=
resourceRaw
.
toResource
()
return
resource
,
nil
}
...
...
@@ -91,13 +104,13 @@ func (s *Store) FindResourceList(ctx context.Context, find *api.ResourceFind) ([
func
(
s
*
Store
)
FindResource
(
ctx
context
.
Context
,
find
*
api
.
ResourceFind
)
(
*
api
.
Resource
,
error
)
{
if
find
.
ID
!=
nil
{
resource
:=
&
api
.
Resource
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ResourceCache
,
*
find
.
ID
,
resource
)
resource
Raw
:=
&
resourceRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ResourceCache
,
*
find
.
ID
,
resource
Raw
)
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
return
resource
,
nil
return
resource
Raw
.
toResource
()
,
nil
}
}
...
...
@@ -116,12 +129,14 @@ func (s *Store) FindResource(ctx context.Context, find *api.ResourceFind) (*api.
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"not found"
)}
}
resource
:=
list
[
0
]
.
toResource
()
resource
Raw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resource
.
ID
,
resource
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ResourceCache
,
resource
Raw
.
ID
,
resourceRaw
);
err
!=
nil
{
return
nil
,
err
}
resource
:=
resourceRaw
.
toResource
()
return
resource
,
nil
}
...
...
store/shortcut.go
View file @
9f8c0ce5
...
...
@@ -56,12 +56,12 @@ func (s *Store) CreateShortcut(ctx context.Context, create *api.ShortcutCreate)
return
nil
,
FormatError
(
err
)
}
shortcut
:=
shortcutRaw
.
toShortcut
()
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcut
.
ID
,
shortcut
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
shortcut
:=
shortcutRaw
.
toShortcut
()
return
shortcut
,
nil
}
...
...
@@ -81,12 +81,12 @@ func (s *Store) PatchShortcut(ctx context.Context, patch *api.ShortcutPatch) (*a
return
nil
,
FormatError
(
err
)
}
shortcut
:=
shortcutRaw
.
toShortcut
()
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcut
.
ID
,
shortcut
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcutRaw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
shortcut
:=
shortcutRaw
.
toShortcut
()
return
shortcut
,
nil
}
...
...
@@ -112,13 +112,13 @@ func (s *Store) FindShortcutList(ctx context.Context, find *api.ShortcutFind) ([
func
(
s
*
Store
)
FindShortcut
(
ctx
context
.
Context
,
find
*
api
.
ShortcutFind
)
(
*
api
.
Shortcut
,
error
)
{
if
find
.
ID
!=
nil
{
shortcut
:=
&
api
.
Shortcut
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ShortcutCache
,
*
find
.
ID
,
shortcut
)
shortcut
Raw
:=
&
shortcutRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
ShortcutCache
,
*
find
.
ID
,
shortcut
Raw
)
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
return
shortcut
,
nil
return
shortcut
Raw
.
toShortcut
()
,
nil
}
}
...
...
@@ -137,12 +137,14 @@ func (s *Store) FindShortcut(ctx context.Context, find *api.ShortcutFind) (*api.
return
nil
,
&
common
.
Error
{
Code
:
common
.
NotFound
,
Err
:
fmt
.
Errorf
(
"not found"
)}
}
shortcut
:=
list
[
0
]
.
toShortcut
()
shortcut
Raw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcut
.
ID
,
shortcut
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
ShortcutCache
,
shortcut
Raw
.
ID
,
shortcutRaw
);
err
!=
nil
{
return
nil
,
err
}
shortcut
:=
shortcutRaw
.
toShortcut
()
return
shortcut
,
nil
}
...
...
store/user.go
View file @
9f8c0ce5
...
...
@@ -51,6 +51,7 @@ func (s *Store) ComposeMemoCreator(ctx context.Context, memo *api.Memo) error {
if
err
!=
nil
{
return
err
}
user
.
OpenID
=
""
user
.
UserSettingList
=
nil
memo
.
Creator
=
user
...
...
@@ -74,12 +75,12 @@ func (s *Store) CreateUser(ctx context.Context, create *api.UserCreate) (*api.Us
return
nil
,
FormatError
(
err
)
}
user
:=
userRaw
.
toUser
()
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
user
.
ID
,
user
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
user
:=
userRaw
.
toUser
()
return
user
,
nil
}
...
...
@@ -99,12 +100,12 @@ func (s *Store) PatchUser(ctx context.Context, patch *api.UserPatch) (*api.User,
return
nil
,
FormatError
(
err
)
}
user
:=
userRaw
.
toUser
()
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
user
.
ID
,
user
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
userRaw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
user
:=
userRaw
.
toUser
()
return
user
,
nil
}
...
...
@@ -130,13 +131,13 @@ func (s *Store) FindUserList(ctx context.Context, find *api.UserFind) ([]*api.Us
func
(
s
*
Store
)
FindUser
(
ctx
context
.
Context
,
find
*
api
.
UserFind
)
(
*
api
.
User
,
error
)
{
if
find
.
ID
!=
nil
{
user
:=
&
api
.
User
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
UserCache
,
*
find
.
ID
,
user
)
user
Raw
:=
&
userRaw
{}
has
,
err
:=
s
.
cache
.
FindCache
(
api
.
UserCache
,
*
find
.
ID
,
user
Raw
)
if
err
!=
nil
{
return
nil
,
err
}
if
has
{
return
user
,
nil
return
user
Raw
.
toUser
()
,
nil
}
}
...
...
@@ -157,12 +158,14 @@ func (s *Store) FindUser(ctx context.Context, find *api.UserFind) (*api.User, er
return
nil
,
&
common
.
Error
{
Code
:
common
.
Conflict
,
Err
:
fmt
.
Errorf
(
"found %d users with filter %+v, expect 1"
,
len
(
list
),
find
)}
}
user
:=
list
[
0
]
.
toUser
()
user
Raw
:=
list
[
0
]
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
user
.
ID
,
user
);
err
!=
nil
{
if
err
:=
s
.
cache
.
UpsertCache
(
api
.
UserCache
,
user
Raw
.
ID
,
userRaw
);
err
!=
nil
{
return
nil
,
err
}
user
:=
userRaw
.
toUser
()
return
user
,
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