Avoid caching empty reply/note lists

This commit is contained in:
Daniele Tonon
2023-07-14 14:46:32 +02:00
parent 9272d09048
commit 197ef89e3e
2 changed files with 6 additions and 2 deletions

View File

@@ -172,7 +172,9 @@ func relaysForPubkey(ctx context.Context, pubkey string, extraRelays ...string)
}
}
cancel()
cache.SetJSONWithTTL("io:"+pubkey, pubkeyRelays, time.Hour*24*7)
if len(pubkeyRelays) > 0 {
cache.SetJSONWithTTL("io:"+pubkey, pubkeyRelays, time.Hour*24*7)
}
}
return pubkeyRelays
}

View File

@@ -107,7 +107,9 @@ func render(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), time.Second*4)
lastNotes = getLastNotes(ctx, code, events_num)
cancel()
cache.SetJSONWithTTL(key, lastNotes, time.Hour*24)
if len(lastNotes) > 0 {
cache.SetJSONWithTTL(key, lastNotes, time.Hour*24)
}
}
renderableLastNotes = make([]*Event, len(lastNotes))