Search Apps Documentation Source Content File Folder Download Copy Actions Download

config.gno

1.40 Kb · 67 lines
 1package chunk
 2
 3import (
 4	"chain"
 5	"strconv"
 6
 7	"gno.land/p/akkadia/v0/accesscontrol"
 8	"gno.land/r/akkadia/v0/admin"
 9)
10
11const (
12	SetListLimitEvent  = "SetListLimit"
13	SetBatchLimitEvent = "SetBatchLimit"
14
15	// Coord keys only use digits, '-', and '_', so '~' is a stable high bound.
16	coordKeyUpperBound = "~"
17)
18
19var (
20	listLimit  int = 100  // Max items per list query
21	batchLimit int = 1000 // Max keys per batch query
22	frozen     bool
23)
24
25// SetListLimit sets the max items per list query (admin only)
26func SetListLimit(cur realm, limit int) {
27	assertNotFrozen()
28	accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
29	assertPositiveLimit(limit)
30
31	oldLimit := listLimit
32	listLimit = limit
33
34	chain.Emit(
35		SetListLimitEvent,
36		"oldLimit", strconv.Itoa(oldLimit),
37		"newLimit", strconv.Itoa(limit),
38	)
39}
40
41// GetListLimit returns the max items per list query
42func GetListLimit() int {
43	assertMigrationStateAvailable()
44	return listLimit
45}
46
47// SetBatchLimit sets the max keys per batch query (admin only)
48func SetBatchLimit(cur realm, limit int) {
49	assertNotFrozen()
50	accesscontrol.AssertIsAdmin(0, cur, admin.IsAdmin)
51	assertPositiveLimit(limit)
52
53	oldLimit := batchLimit
54	batchLimit = limit
55
56	chain.Emit(
57		SetBatchLimitEvent,
58		"oldLimit", strconv.Itoa(oldLimit),
59		"newLimit", strconv.Itoa(limit),
60	)
61}
62
63// GetBatchLimit returns the max keys per batch query
64func GetBatchLimit() int {
65	assertMigrationStateAvailable()
66	return batchLimit
67}