mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-03 04:03:09 -06:00
Use map[string]time.Duration to specify different expiry times
This commit is contained in:
parent
778b981879
commit
3bc192a7d5
|
|
@ -27,10 +27,9 @@ import (
|
||||||
|
|
||||||
// expireEDUTypes contains EDUs which can/should be expired after a given time
|
// expireEDUTypes contains EDUs which can/should be expired after a given time
|
||||||
// if the target server isn't reachable for some reason.
|
// if the target server isn't reachable for some reason.
|
||||||
var expireEDUTypes = map[string]struct{}{
|
var expireEDUTypes = map[string]time.Duration{
|
||||||
gomatrixserverlib.MTyping: {},
|
gomatrixserverlib.MTyping: time.Minute,
|
||||||
gomatrixserverlib.MPresence: {},
|
gomatrixserverlib.MPresence: time.Minute * 10,
|
||||||
gomatrixserverlib.MReceipt: {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssociateEDUWithDestination creates an association that the
|
// AssociateEDUWithDestination creates an association that the
|
||||||
|
|
@ -43,9 +42,9 @@ func (d *Database) AssociateEDUWithDestination(
|
||||||
eduType string,
|
eduType string,
|
||||||
) error {
|
) error {
|
||||||
var expiresAt *gomatrixserverlib.Timestamp
|
var expiresAt *gomatrixserverlib.Timestamp
|
||||||
if _, ok := expireEDUTypes[eduType]; ok {
|
if duration, ok := expireEDUTypes[eduType]; ok {
|
||||||
// Keep EDUs for at least one hour before deleting them
|
// Keep EDUs for at least x minutes before deleting them
|
||||||
ts := gomatrixserverlib.AsTimestamp(time.Now().Add(time.Hour))
|
ts := gomatrixserverlib.AsTimestamp(time.Now().Add(duration))
|
||||||
expiresAt = &ts
|
expiresAt = &ts
|
||||||
}
|
}
|
||||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue