Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: Add routes page sizes as plugin settings. #1604

Merged
merged 5 commits into from Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 40 additions & 12 deletions politeiad/backendv2/tstorebe/plugins/comments/comments.go
Expand Up @@ -40,9 +40,11 @@ type commentsPlugin struct {
identity *identity.FullIdentity

// Plugin settings
commentLengthMax uint32
voteChangesMax uint32
allowExtraData bool
commentLengthMax uint32
voteChangesMax uint32
allowExtraData bool
countPageSize uint32
timestampsPageSize uint32
}

// Setup performs any plugin setup that is required.
Expand Down Expand Up @@ -155,6 +157,14 @@ func (p *commentsPlugin) Settings() []backend.PluginSetting {
Key: comments.SettingKeyAllowExtraData,
Value: strconv.FormatBool(p.allowExtraData),
},
{
Key: comments.SettingKeyCountPageSize,
Value: strconv.FormatUint(uint64(p.countPageSize), 10),
},
{
Key: comments.SettingKeyTimestampsPageSize,
Value: strconv.FormatUint(uint64(p.timestampsPageSize), 10),
},
}
}

Expand All @@ -169,9 +179,11 @@ func New(tstore plugins.TstoreClient, settings []backend.PluginSetting, dataDir

// Default plugin settings
var (
commentLengthMax = comments.SettingCommentLengthMax
voteChangesMax = comments.SettingVoteChangesMax
allowExtraData = comments.SettingAllowExtraData
commentLengthMax = comments.SettingCommentLengthMax
voteChangesMax = comments.SettingVoteChangesMax
allowExtraData = comments.SettingAllowExtraData
countPageSize = comments.SettingCountPageSize
timestampsPageSize = comments.SettingTimestampsPageSize
)

// Override defaults with any passed in settings
Expand All @@ -198,17 +210,33 @@ func New(tstore plugins.TstoreClient, settings []backend.PluginSetting, dataDir
v.Key, v.Value, err)
}
allowExtraData = b
case comments.SettingKeyCountPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, errors.Errorf("invalid plugin setting %v '%v': %v",
v.Key, v.Value, err)
}
countPageSize = uint32(u)
case comments.SettingKeyTimestampsPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, errors.Errorf("invalid plugin setting %v '%v': %v",
v.Key, v.Value, err)
}
timestampsPageSize = uint32(u)
default:
return nil, errors.Errorf("invalid comments plugin setting '%v'", v.Key)
}
}

return &commentsPlugin{
tstore: tstore,
identity: id,
dataDir: dataDir,
commentLengthMax: commentLengthMax,
voteChangesMax: voteChangesMax,
allowExtraData: allowExtraData,
tstore: tstore,
identity: id,
dataDir: dataDir,
commentLengthMax: commentLengthMax,
voteChangesMax: voteChangesMax,
allowExtraData: allowExtraData,
countPageSize: countPageSize,
timestampsPageSize: timestampsPageSize,
}, nil
}
118 changes: 73 additions & 45 deletions politeiad/backendv2/tstorebe/plugins/pi/pi.go
Expand Up @@ -49,21 +49,23 @@ type piPlugin struct {
identity *identity.FullIdentity

// Plugin settings
textFileCountMax uint32
textFileSizeMax uint32 // In bytes
imageFileCountMax uint32
imageFileSizeMax uint32 // In bytes
titleSupportedChars string // JSON encoded []string
titleLengthMin uint32 // In characters
titleLengthMax uint32 // In characters
titleRegexp *regexp.Regexp
proposalAmountMin uint64 // In cents
proposalAmountMax uint64 // In cents
proposalStartDateMin int64 // Seconds from current time
proposalEndDateMax int64 // Seconds from current time
proposalDomainsEncoded string // JSON encoded []string
proposalDomains map[string]struct{}
billingStatusChangesMax uint32
textFileCountMax uint32
textFileSizeMax uint32 // In bytes
imageFileCountMax uint32
imageFileSizeMax uint32 // In bytes
titleSupportedChars string // JSON encoded []string
titleLengthMin uint32 // In characters
titleLengthMax uint32 // In characters
titleRegexp *regexp.Regexp
proposalAmountMin uint64 // In cents
proposalAmountMax uint64 // In cents
proposalStartDateMin int64 // Seconds from current time
proposalEndDateMax int64 // Seconds from current time
proposalDomainsEncoded string // JSON encoded []string
proposalDomains map[string]struct{}
billingStatusChangesMax uint32
summariesPageSize uint32
billingStatusChangesPageSize uint32
}

// Setup performs any plugin setup that is required.
Expand Down Expand Up @@ -180,6 +182,14 @@ func (p *piPlugin) Settings() []backend.PluginSetting {
Key: pi.SettingKeyBillingStatusChangesMax,
Value: strconv.FormatUint(uint64(p.billingStatusChangesMax), 10),
},
{
Key: pi.SettingKeySummariesPageSize,
Value: strconv.FormatUint(uint64(p.summariesPageSize), 10),
},
{
Key: pi.SettingKeyBillingStatusChangesPageSize,
Value: strconv.FormatUint(uint64(p.billingStatusChangesPageSize), 10),
},
}
}

Expand All @@ -194,18 +204,20 @@ func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backen

// Setup plugin setting default values
var (
textFileSizeMax = pi.SettingTextFileSizeMax
imageFileCountMax = pi.SettingImageFileCountMax
imageFileSizeMax = pi.SettingImageFileSizeMax
titleLengthMin = pi.SettingTitleLengthMin
titleLengthMax = pi.SettingTitleLengthMax
titleSupportedChars = pi.SettingTitleSupportedChars
amountMin = pi.SettingProposalAmountMin
amountMax = pi.SettingProposalAmountMax
startDateMin = pi.SettingProposalStartDateMin
endDateMax = pi.SettingProposalEndDateMax
domains = pi.SettingProposalDomains
billingStatusChangesMax = pi.SettingBillingStatusChangesMax
textFileSizeMax = pi.SettingTextFileSizeMax
imageFileCountMax = pi.SettingImageFileCountMax
imageFileSizeMax = pi.SettingImageFileSizeMax
titleLengthMin = pi.SettingTitleLengthMin
titleLengthMax = pi.SettingTitleLengthMax
titleSupportedChars = pi.SettingTitleSupportedChars
amountMin = pi.SettingProposalAmountMin
amountMax = pi.SettingProposalAmountMax
startDateMin = pi.SettingProposalStartDateMin
endDateMax = pi.SettingProposalEndDateMax
domains = pi.SettingProposalDomains
billingStatusChangesMax = pi.SettingBillingStatusChangesMax
summariesPageSize = pi.SettingSummariesPageSize
billingStatusChangesPageSize = pi.SettingBillingStatusChangesPageSize
)

// Override defaults with any passed in settings
Expand Down Expand Up @@ -291,6 +303,20 @@ func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backen
v.Key, v.Value, err)
}
billingStatusChangesMax = uint32(u)
case pi.SettingKeySummariesPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, errors.Errorf("invalid plugin setting %v '%v': %v",
v.Key, v.Value, err)
}
summariesPageSize = uint32(u)
case pi.SettingKeyBillingStatusChangesPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, errors.Errorf("invalid plugin setting %v '%v': %v",
v.Key, v.Value, err)
}
billingStatusChangesPageSize = uint32(u)

default:
return nil, errors.Errorf("invalid plugin setting: %v", v.Key)
Expand Down Expand Up @@ -327,24 +353,26 @@ func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backen
}

return &piPlugin{
dataDir: dataDir,
identity: id,
backend: backend,
textFileSizeMax: textFileSizeMax,
tstore: tstore,
imageFileCountMax: imageFileCountMax,
imageFileSizeMax: imageFileSizeMax,
titleLengthMin: titleLengthMin,
titleLengthMax: titleLengthMax,
titleSupportedChars: titleSupportedCharsString,
titleRegexp: rexp,
proposalAmountMin: amountMin,
proposalAmountMax: amountMax,
proposalStartDateMin: startDateMin,
proposalEndDateMax: endDateMax,
proposalDomainsEncoded: domainsString,
proposalDomains: domainsMap,
billingStatusChangesMax: billingStatusChangesMax,
dataDir: dataDir,
identity: id,
backend: backend,
textFileSizeMax: textFileSizeMax,
tstore: tstore,
imageFileCountMax: imageFileCountMax,
imageFileSizeMax: imageFileSizeMax,
titleLengthMin: titleLengthMin,
titleLengthMax: titleLengthMax,
titleSupportedChars: titleSupportedCharsString,
titleRegexp: rexp,
proposalAmountMin: amountMin,
proposalAmountMax: amountMax,
proposalStartDateMin: startDateMin,
proposalEndDateMax: endDateMax,
proposalDomainsEncoded: domainsString,
proposalDomains: domainsMap,
billingStatusChangesMax: billingStatusChangesMax,
summariesPageSize: summariesPageSize,
billingStatusChangesPageSize: billingStatusChangesPageSize,
statuses: proposalStatuses{
data: make(map[string]*statusEntry, statusesCacheLimit),
entries: list.New(),
Expand Down
87 changes: 69 additions & 18 deletions politeiad/backendv2/tstorebe/plugins/ticketvote/ticketvote.go
Expand Up @@ -57,10 +57,13 @@ type ticketVotePlugin struct {
mtxSubs sync.Mutex // Runoff vote submission cache

// Plugin settings
linkByPeriodMin int64 // In seconds
linkByPeriodMax int64 // In seconds
voteDurationMin uint32 // In blocks
voteDurationMax uint32 // In blocks
linkByPeriodMin int64 // In seconds
linkByPeriodMax int64 // In seconds
voteDurationMin uint32 // In blocks
voteDurationMax uint32 // In blocks
summariesPageSize uint32
inventoryPageSize uint32
timestampsPageSize uint32
}

// Setup performs any plugin setup that is required.
Expand Down Expand Up @@ -487,16 +490,31 @@ func (p *ticketVotePlugin) Settings() []backend.PluginSetting {
Key: ticketvote.SettingKeyVoteDurationMax,
Value: strconv.FormatUint(uint64(p.voteDurationMax), 10),
},
{
Key: ticketvote.SettingKeySummariesPageSize,
Value: strconv.FormatUint(uint64(p.summariesPageSize), 10),
},
{
Key: ticketvote.SettingKeyInventoryPageSize,
Value: strconv.FormatUint(uint64(p.inventoryPageSize), 10),
},
{
Key: ticketvote.SettingKeyTimestampsPageSize,
Value: strconv.FormatUint(uint64(p.timestampsPageSize), 10),
},
}
}

func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backend.PluginSetting, dataDir string, id *identity.FullIdentity, activeNetParams *chaincfg.Params) (*ticketVotePlugin, error) {
// Plugin settings
var (
linkByPeriodMin int64
linkByPeriodMax int64
voteDurationMin uint32
voteDurationMax uint32
linkByPeriodMin int64
linkByPeriodMax int64
voteDurationMin uint32
voteDurationMax uint32
summariesPageSize = ticketvote.SettingSummariesPageSize
inventoryPageSize = ticketvote.SettingInventoryPageSize
timestampsPageSize = ticketvote.SettingTimestampsPageSize
)

// Set plugin settings to defaults. These will be overwritten if
Expand Down Expand Up @@ -565,6 +583,36 @@ func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backen
log.Infof("Plugin setting updated: ticketvote %v %v",
ticketvote.SettingKeyVoteDurationMax, voteDurationMax)

case ticketvote.SettingKeySummariesPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, fmt.Errorf("plugin setting '%v': ParseUint(%v): %v",
v.Key, v.Value, err)
}
summariesPageSize = uint32(u)
log.Infof("Plugin setting updated: ticketvote %v %v",
ticketvote.SettingKeySummariesPageSize, summariesPageSize)

case ticketvote.SettingKeyInventoryPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, fmt.Errorf("plugin setting '%v': ParseUint(%v): %v",
v.Key, v.Value, err)
}
inventoryPageSize = uint32(u)
log.Infof("Plugin setting updated: ticketvote %v %v",
ticketvote.SettingKeyInventoryPageSize, inventoryPageSize)

case ticketvote.SettingKeyTimestampsPageSize:
u, err := strconv.ParseUint(v.Value, 10, 64)
if err != nil {
return nil, fmt.Errorf("plugin setting '%v': ParseUint(%v): %v",
v.Key, v.Value, err)
}
timestampsPageSize = uint32(u)
log.Infof("Plugin setting updated: ticketvote %v %v",
ticketvote.SettingKeyTimestampsPageSize, timestampsPageSize)

default:
return nil, fmt.Errorf("invalid plugin setting '%v'", v.Key)
}
Expand All @@ -578,15 +626,18 @@ func New(backend backend.Backend, tstore plugins.TstoreClient, settings []backen
}

return &ticketVotePlugin{
activeNetParams: activeNetParams,
backend: backend,
tstore: tstore,
dataDir: dataDir,
identity: id,
activeVotes: newActiveVotes(),
linkByPeriodMin: linkByPeriodMin,
linkByPeriodMax: linkByPeriodMax,
voteDurationMin: voteDurationMin,
voteDurationMax: voteDurationMax,
activeNetParams: activeNetParams,
backend: backend,
tstore: tstore,
dataDir: dataDir,
identity: id,
activeVotes: newActiveVotes(),
linkByPeriodMin: linkByPeriodMin,
linkByPeriodMax: linkByPeriodMax,
voteDurationMin: voteDurationMin,
voteDurationMax: voteDurationMax,
summariesPageSize: summariesPageSize,
inventoryPageSize: inventoryPageSize,
timestampsPageSize: timestampsPageSize,
}, nil
}
16 changes: 16 additions & 0 deletions politeiad/plugins/comments/comments.go
Expand Up @@ -38,6 +38,14 @@ const (
// SettingKeyAllowExtraData is the plugin setting key for the
// SettingAllowExtraData plugin setting.
SettingKeyAllowExtraData = "allowextradata"

// SettingKeyCountPageSize is the plugin setting key for the
// SettingCountPageSize plugin setting.
SettingKeyCountPageSize = "countpagesize"

// SettingKeyTimestampsPageSize is the plugin setting key for the
// SettingTimestampsPageSize plugin setting.
SettingKeyTimestampsPageSize = "timestampspagesize"
)

// Plugin setting default values. These can be overridden by providing a plugin
Expand All @@ -55,6 +63,14 @@ const (
// SettingAllowExtraData is the default value of the bool flag which
// determines whether posting extra data along with the comment is allowed.
SettingAllowExtraData = false

// SettingCountPageSize is the default maximum number of comment counts
// that can be requested at any one time.
SettingCountPageSize uint32 = 10

// SettingTimestampsPageSize is the default maximum number of comment
// timestamps that can be requested at any one time.
SettingTimestampsPageSize uint32 = 100
)

// ErrorCodeT represents a error that was caused by the user.
Expand Down