all repos — underbbs @ bcfe1587c944b2faecec4b961f6ff91581181279

decentralized social media client

MisskeyAdapter: add author cache
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZsDWUgAKCRBohAcXSWbK
8+22AQCG6gUxV42kSLZisnoDGZ5xxLKUqcvVGVtxNW9b1ilx3gD/VbRTOB4basT1
WDAzn+rRpqQ4+pVJ8ITDfGLWRV5RPwE=
=H5TP
-----END PGP SIGNATURE-----
commit

bcfe1587c944b2faecec4b961f6ff91581181279

parent

aecfd97c96bef0ed18720c9db1dba360990f3ec5

1 files changed, 34 insertions(+), 20 deletions(-)

jump to
M adapter/misskey.goadapter/misskey.go

@@ -99,8 +99,8 @@ if !ok {

return } default: - notesService = self.mk.Notes() - timelineService = notesService.Timeline() + notesService = self.mk.Notes() + timelineService = notesService.Timeline() // TODO: we have to actually decode and pass our filter criteria // probe for new notes

@@ -232,8 +232,8 @@ }

return nil } -func (self *MisskeyAdapter) toAuthor(usr mkm.User) *Author { - fmt.Println("converting author: " + usr.ID) +func (self *MisskeyAdapter) toAuthor(usr mkm.User, bustCache bool) *Author { + host := mkcore.StringValue(usr.Host) authorId := "" if host != "" {

@@ -242,28 +242,42 @@ } else {

authorId = fmt.Sprintf("@%s", usr.Username) } + self.mtx.RLock() + timestamp, exists := self.cache[authorId] + self.mtx.RUnlock() + var updated *int64 = nil if usr.UpdatedAt != nil { updatedTmp := usr.UpdatedAt.UnixMilli() updated = &updatedTmp } - author := Author{ - Datagram: Datagram{ - Id: authorId, - Uri: mkcore.StringValue(usr.URL), - Protocol: "misskey", - Adapter: self.nickname, - Type: "author", - Created: usr.CreatedAt.UnixMilli(), - Updated: updated, - }, - Name: usr.Name, - ProfilePic: usr.AvatarURL, - ProfileData: usr.Description, - } + 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 + } - return &author + author := Author{ + Datagram: Datagram{ + Id: authorId, + Uri: mkcore.StringValue(usr.URL), + Protocol: "misskey", + Adapter: self.nickname, + Type: "author", + Created: usr.CreatedAt.UnixMilli(), + Updated: updated, + }, + Name: usr.Name, + ProfilePic: usr.AvatarURL, + ProfileData: usr.Description, + } + + return &author + } + return nil } func (self *MisskeyAdapter) Fetch(etype string, ids []string) error {

@@ -331,7 +345,7 @@ })

if err != nil { return err } else { - a := self.toAuthor(data) + a := self.toAuthor(data, false) if a != nil { self.data <- a }