refactor: rename parameter from maxDays to maxDuration

This commit is contained in:
Richard Ramos 2021-11-06 09:23:58 -04:00
parent a7c76d2af1
commit 2cbedf47a0
4 changed files with 14 additions and 13 deletions

View File

@ -144,7 +144,7 @@ func Execute(options Options) {
}
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 {
dbStore, err := persistence.NewDBStore(persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration()))
failOnErr(err, "DBStore")

View File

@ -21,7 +21,7 @@ type DBStore struct {
db *sql.DB
maxMessages int
maxDays time.Duration
maxDuration time.Duration
}
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 {
d.maxDays = maxDays
d.maxDuration = maxDuration
d.maxMessages = maxMessages
return nil
}
}
// 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) {
result := new(DBStore)
@ -105,10 +106,10 @@ func (d *DBStore) createTable() error {
}
func (d *DBStore) cleanOlderRecords() error {
// Delete messages older than N days
if d.maxDays > 0 {
// Delete older messages
if d.maxDuration > 0 {
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 {
return err
}

View File

@ -128,7 +128,7 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, 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 {
w.startStore()
}

View File

@ -38,7 +38,7 @@ type WakuNodeParameters struct {
storeMsgs bool
messageProvider store.MessageProvider
maxMessages int
maxDays time.Duration
maxDuration time.Duration
enableRendezvous 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
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 {
params.enableStore = true
params.storeMsgs = true
params.shouldResume = shouldResume
params.maxDays = maxDays
params.maxDuration = maxDuration
params.maxMessages = maxMessages
return nil
}