MisskeyAdapter: add author cache
This commit is contained in:
parent
aecfd97c96
commit
bcfe1587c9
1 changed files with 34 additions and 20 deletions
|
@ -232,8 +232,8 @@ func (self *MisskeyAdapter) toMessage(n mkm.Note, bustCache bool) *Message {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author {
|
func (self *MisskeyAdapter) toAuthor(usr mkm.User, bustCache bool) *Author {
|
||||||
fmt.Println("converting author: " + usr.ID)
|
|
||||||
host := mkcore.StringValue(usr.Host)
|
host := mkcore.StringValue(usr.Host)
|
||||||
authorId := ""
|
authorId := ""
|
||||||
if host != "" {
|
if host != "" {
|
||||||
|
@ -242,12 +242,24 @@ func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author {
|
||||||
authorId = fmt.Sprintf("@%s", usr.Username)
|
authorId = fmt.Sprintf("@%s", usr.Username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.mtx.RLock()
|
||||||
|
timestamp, exists := self.cache[authorId]
|
||||||
|
self.mtx.RUnlock()
|
||||||
|
|
||||||
var updated *int64 = nil
|
var updated *int64 = nil
|
||||||
if usr.UpdatedAt != nil {
|
if usr.UpdatedAt != nil {
|
||||||
updatedTmp := usr.UpdatedAt.UnixMilli()
|
updatedTmp := usr.UpdatedAt.UnixMilli()
|
||||||
updated = &updatedTmp
|
updated = &updatedTmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bustCache || !exists || (updated != nil && timestamp.Before(time.UnixMilli(*updated))) || timestamp.Before(*usr.CreatedAt) {
|
||||||
|
fmt.Println("converting author: " + usr.ID)
|
||||||
|
if usr.UpdatedAt != nil {
|
||||||
|
self.cache[authorId] = *usr.UpdatedAt
|
||||||
|
} else {
|
||||||
|
self.cache[authorId] = *usr.CreatedAt
|
||||||
|
}
|
||||||
|
|
||||||
author := Author{
|
author := Author{
|
||||||
Datagram: Datagram{
|
Datagram: Datagram{
|
||||||
Id: authorId,
|
Id: authorId,
|
||||||
|
@ -265,6 +277,8 @@ func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author {
|
||||||
|
|
||||||
return &author
|
return &author
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *MisskeyAdapter) Fetch(etype string, ids []string) error {
|
func (self *MisskeyAdapter) Fetch(etype string, ids []string) error {
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
|
@ -331,7 +345,7 @@ func (self *MisskeyAdapter) Fetch(etype string, ids []string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
a := self.toAuthor(data)
|
a := self.toAuthor(data, false)
|
||||||
if a != nil {
|
if a != nil {
|
||||||
self.data <- a
|
self.data <- a
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue