aboutsummaryrefslogtreecommitdiff
path: root/federationapi/storage
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-08-18 12:14:42 +0200
committerGitHub <noreply@github.com>2022-08-18 11:14:42 +0100
commit7484689ad124c5759c8a10bebaabe9265602fd7d (patch)
treea79a21c82264605ec2bdec1861058b5035a1eb47 /federationapi/storage
parent59bc0a6f4ed0324da0387118e1761b4551aaf103 (diff)
Actually store EDUs once we retrieved from the database (#2651)
We now actually cache the EDUs once we got them from the database and ensures we only evict them if we successfully deleted them.
Diffstat (limited to 'federationapi/storage')
-rw-r--r--federationapi/storage/shared/storage_edus.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/federationapi/storage/shared/storage_edus.go b/federationapi/storage/shared/storage_edus.go
index b62e5d9c..ce9632ed 100644
--- a/federationapi/storage/shared/storage_edus.go
+++ b/federationapi/storage/shared/storage_edus.go
@@ -110,6 +110,7 @@ func (d *Database) GetPendingEDUs(
return fmt.Errorf("json.Unmarshal: %w", err)
}
edus[&Receipt{nid}] = &event
+ d.Cache.StoreFederationQueuedEDU(nid, &event)
}
return nil
@@ -177,20 +178,18 @@ func (d *Database) GetPendingEDUServerNames(
return d.FederationQueueEDUs.SelectQueueEDUServerNames(ctx, nil)
}
-// DeleteExpiredEDUs deletes expired EDUs
+// DeleteExpiredEDUs deletes expired EDUs and evicts them from the cache.
func (d *Database) DeleteExpiredEDUs(ctx context.Context) error {
- return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
+ var jsonNIDs []int64
+ err := d.Writer.Do(d.DB, nil, func(txn *sql.Tx) (err error) {
expiredBefore := gomatrixserverlib.AsTimestamp(time.Now())
- jsonNIDs, err := d.FederationQueueEDUs.SelectExpiredEDUs(ctx, txn, expiredBefore)
+ jsonNIDs, err = d.FederationQueueEDUs.SelectExpiredEDUs(ctx, txn, expiredBefore)
if err != nil {
return err
}
if len(jsonNIDs) == 0 {
return nil
}
- for i := range jsonNIDs {
- d.Cache.EvictFederationQueuedEDU(jsonNIDs[i])
- }
if err = d.FederationQueueJSON.DeleteQueueJSON(ctx, txn, jsonNIDs); err != nil {
return err
@@ -198,4 +197,14 @@ func (d *Database) DeleteExpiredEDUs(ctx context.Context) error {
return d.FederationQueueEDUs.DeleteExpiredEDUs(ctx, txn, expiredBefore)
})
+
+ if err != nil {
+ return err
+ }
+
+ for i := range jsonNIDs {
+ d.Cache.EvictFederationQueuedEDU(jsonNIDs[i])
+ }
+
+ return nil
}