Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aon-tg-messenger
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Odysseus
aon-tg-messenger
Commits
6300183e
Commit
6300183e
authored
Aug 06, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update supported chats cache
parent
873e75af
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
db.go
dao/db.go
+23
-1
No files found.
dao/db.go
View file @
6300183e
...
...
@@ -3,6 +3,8 @@ package dao
import
(
"fmt"
dbModel
"sdk_api/model/db"
"sync"
"time"
"gorm.io/gorm"
"gorm.io/gorm/clause"
...
...
@@ -59,7 +61,19 @@ func (d *Dao) UserLeft(userId, chatId int) (err error) {
Update
(
"left_at"
,
gorm
.
Expr
(
"NOW()"
))
.
Error
}
var
(
supportedChatsCache
=
map
[
int
]
time
.
Time
{}
supportedChatsCacheLock
=
sync
.
RWMutex
{}
)
func
(
d
*
Dao
)
IsSupportedChat
(
chatId
int
)
(
exist
bool
,
err
error
)
{
supportedChatsCacheLock
.
RLock
()
expired
,
ok
:=
supportedChatsCache
[
chatId
]
supportedChatsCacheLock
.
RUnlock
()
if
ok
&&
expired
.
After
(
time
.
Now
())
{
return
true
,
nil
}
a
:=
dbModel
.
ChatGroup
{}
err
=
d
.
db
.
Model
(
&
dbModel
.
ChatGroup
{})
.
Where
(
"chat_id = ?"
,
chatId
)
.
...
...
@@ -67,7 +81,15 @@ func (d *Dao) IsSupportedChat(chatId int) (exist bool, err error) {
if
err
==
gorm
.
ErrRecordNotFound
{
return
false
,
nil
}
return
err
==
nil
,
err
if
err
!=
nil
{
return
false
,
err
}
supportedChatsCacheLock
.
Lock
()
supportedChatsCache
[
chatId
]
=
time
.
Now
()
.
Add
(
1
*
time
.
Hour
)
supportedChatsCacheLock
.
Unlock
()
return
true
,
err
}
func
(
d
*
Dao
)
addTestGroup
()
(
err
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