mirror of https://github.com/status-im/go-waku.git
refactor: rename parameter from maxDays to maxDuration
This commit is contained in:
parent
a7c76d2af1
commit
2cbedf47a0
|
@ -144,7 +144,7 @@ func Execute(options Options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.Store.Enable {
|
if options.Store.Enable {
|
||||||
nodeOpts = append(nodeOpts, node.WithWakuStoreAndLimits(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages))
|
nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages))
|
||||||
if options.UseDB {
|
if options.UseDB {
|
||||||
dbStore, err := persistence.NewDBStore(persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration()))
|
dbStore, err := persistence.NewDBStore(persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration()))
|
||||||
failOnErr(err, "DBStore")
|
failOnErr(err, "DBStore")
|
||||||
|
|
|
@ -21,7 +21,7 @@ type DBStore struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
|
||||||
maxMessages int
|
maxMessages int
|
||||||
maxDays time.Duration
|
maxDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoredMessage struct {
|
type StoredMessage struct {
|
||||||
|
@ -54,16 +54,17 @@ func WithDriver(driverName string, datasourceName string) DBOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithRetentionPolicy(maxMessages int, maxDays time.Duration) DBOption {
|
func WithRetentionPolicy(maxMessages int, maxDuration time.Duration) DBOption {
|
||||||
return func(d *DBStore) error {
|
return func(d *DBStore) error {
|
||||||
d.maxDays = maxDays
|
d.maxDuration = maxDuration
|
||||||
d.maxMessages = maxMessages
|
d.maxMessages = maxMessages
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new DB store using the db specified via options.
|
// Creates a new DB store using the db specified via options.
|
||||||
// It will create a messages table if it does not exist
|
// It will create a messages table if it does not exist and
|
||||||
|
// clean up records according to the retention policy used
|
||||||
func NewDBStore(options ...DBOption) (*DBStore, error) {
|
func NewDBStore(options ...DBOption) (*DBStore, error) {
|
||||||
result := new(DBStore)
|
result := new(DBStore)
|
||||||
|
|
||||||
|
@ -105,10 +106,10 @@ func (d *DBStore) createTable() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DBStore) cleanOlderRecords() error {
|
func (d *DBStore) cleanOlderRecords() error {
|
||||||
// Delete messages older than N days
|
// Delete older messages
|
||||||
if d.maxDays > 0 {
|
if d.maxDuration > 0 {
|
||||||
sqlStmt := `DELETE FROM message WHERE receiverTimestamp < ?`
|
sqlStmt := `DELETE FROM message WHERE receiverTimestamp < ?`
|
||||||
_, err := d.db.Exec(sqlStmt, utils.GetUnixEpochFrom(func() time.Time { return time.Now().Add(-d.maxDays) }))
|
_, err := d.db.Exec(sqlStmt, utils.GetUnixEpochFrom(func() time.Time { return time.Now().Add(-d.maxDuration) }))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WakuNode) Start() error {
|
func (w *WakuNode) Start() error {
|
||||||
w.store = store.NewWakuStore(w.opts.messageProvider, w.opts.maxMessages, w.opts.maxDays)
|
w.store = store.NewWakuStore(w.opts.messageProvider, w.opts.maxMessages, w.opts.maxDuration)
|
||||||
if w.opts.enableStore {
|
if w.opts.enableStore {
|
||||||
w.startStore()
|
w.startStore()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ type WakuNodeParameters struct {
|
||||||
storeMsgs bool
|
storeMsgs bool
|
||||||
messageProvider store.MessageProvider
|
messageProvider store.MessageProvider
|
||||||
maxMessages int
|
maxMessages int
|
||||||
maxDays time.Duration
|
maxDuration time.Duration
|
||||||
|
|
||||||
enableRendezvous bool
|
enableRendezvous bool
|
||||||
enableRendezvousServer bool
|
enableRendezvousServer bool
|
||||||
|
@ -179,14 +179,14 @@ func WithWakuStore(shouldStoreMessages bool, shouldResume bool) WakuNodeOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithWakuStoreAndLimits enables the Waku V2 Store protocol, storing them in an optional message provider
|
// WithWakuStoreAndRetentionPolicy enables the Waku V2 Store protocol, storing them in an optional message provider
|
||||||
// applying an specific retention policy
|
// applying an specific retention policy
|
||||||
func WithWakuStoreAndLimits(shouldResume bool, maxDays time.Duration, maxMessages int) WakuNodeOption {
|
func WithWakuStoreAndRetentionPolicy(shouldResume bool, maxDuration time.Duration, maxMessages int) WakuNodeOption {
|
||||||
return func(params *WakuNodeParameters) error {
|
return func(params *WakuNodeParameters) error {
|
||||||
params.enableStore = true
|
params.enableStore = true
|
||||||
params.storeMsgs = true
|
params.storeMsgs = true
|
||||||
params.shouldResume = shouldResume
|
params.shouldResume = shouldResume
|
||||||
params.maxDays = maxDays
|
params.maxDuration = maxDuration
|
||||||
params.maxMessages = maxMessages
|
params.maxMessages = maxMessages
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue