slightly improved mentiondb err handling

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
kim (grufwub) 2021-08-27 07:40:13 +01:00
commit 5c9d9e1c54

View file

@ -53,13 +53,13 @@ func (m *mentionDB) mentionCached(id string) (*gtsmodel.Mention, bool) {
} }
mI, err := m.cache.Fetch(id) mI, err := m.cache.Fetch(id)
if err != nil || mI == nil { if err != nil {
return nil, false return nil, false
} }
mention, ok := mI.(*gtsmodel.Mention) mention, ok := mI.(*gtsmodel.Mention)
if !ok { if !ok || mention == nil {
m.log.Panicf("mentionDB: cached interface with key %s was not a mention", id) m.log.Panicf("mentionDB: cached interface with key %s (%T) was not a mention", id, mention)
} }
return mention, true return mention, true
@ -85,12 +85,12 @@ func (m *mentionDB) GetMention(ctx context.Context, id string) (*gtsmodel.Mentio
Where("mention.id = ?", id) Where("mention.id = ?", id)
err := m.conn.ProcessError(q.Scan(ctx)) err := m.conn.ProcessError(q.Scan(ctx))
if err != nil {
if err == nil && mention != nil { return nil, err
m.cacheMention(id, mention)
} }
return mention, err m.cacheMention(id, mention)
return mention, nil
} }
func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.Mention, db.Error) { func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.Mention, db.Error) {
@ -99,7 +99,7 @@ func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.
for _, i := range ids { for _, i := range ids {
mention, err := m.GetMention(ctx, i) mention, err := m.GetMention(ctx, i)
if err != nil { if err != nil {
return nil, m.conn.ProcessError(err) return nil, err
} }
mentions = append(mentions, mention) mentions = append(mentions, mention)
} }