@quenty/aggregator 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +4 -4
- package/src/Shared/Aggregator.lua +27 -15
- package/src/Shared/RateAggregator.lua +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/aggregator@1.1.0...@quenty/aggregator@1.2.0) (2024-12-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add rate aggregation and batching ([8b3b2a6](https://github.com/Quenty/NevermoreEngine/commit/8b3b2a62d5f272980a404b72e2c0d36eae04dfec))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 1.1.0 (2024-12-03)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/aggregator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Aggregates async promise requests",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"@quenty/baseobject": "^10.7.1",
|
|
29
29
|
"@quenty/loader": "^10.7.1",
|
|
30
30
|
"@quenty/lrucache": "^1.5.1",
|
|
31
|
-
"@quenty/promise": "^10.
|
|
31
|
+
"@quenty/promise": "^10.9.0",
|
|
32
32
|
"@quenty/queue": "^2.3.0",
|
|
33
|
-
"@quenty/rx": "^13.
|
|
33
|
+
"@quenty/rx": "^13.15.0",
|
|
34
34
|
"@quenty/tuple": "^1.4.1"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "0a20ace4dc7d38f8c889bf73b716b33e8a767c54"
|
|
40
40
|
}
|
|
@@ -23,24 +23,34 @@ Aggregator.__index = Aggregator
|
|
|
23
23
|
|
|
24
24
|
@return Aggregator<T>
|
|
25
25
|
]=]
|
|
26
|
-
function Aggregator.new(debugName, promiseBulkQuery)
|
|
26
|
+
function Aggregator.new(debugName: string, promiseBulkQuery)
|
|
27
27
|
assert(type(debugName) == "string", "Bad debugName")
|
|
28
28
|
|
|
29
29
|
local self = setmetatable(BaseObject.new(), Aggregator)
|
|
30
30
|
|
|
31
31
|
self._debugName = debugName
|
|
32
|
-
self.
|
|
32
|
+
self._promiseBatchQuery = assert(promiseBulkQuery, "No promiseBulkQuery")
|
|
33
33
|
|
|
34
|
-
-- TODO: LRU cache this? Limit to 1k or something?
|
|
35
34
|
self._promisesLruCache = LRUCache.new(2000)
|
|
36
35
|
|
|
37
|
-
self.
|
|
36
|
+
self._maxBatchSize = 200
|
|
38
37
|
self._unsentCount = 0
|
|
39
38
|
self._unsentPromises = {}
|
|
40
39
|
|
|
41
40
|
return self
|
|
42
41
|
end
|
|
43
42
|
|
|
43
|
+
--[=[
|
|
44
|
+
Sets the max batch size
|
|
45
|
+
@param maxBatchSize number
|
|
46
|
+
]=]
|
|
47
|
+
function Aggregator:SetMaxBatchSize(maxBatchSize: number)
|
|
48
|
+
assert(type(maxBatchSize) == "number", "Bad maxBatchSize")
|
|
49
|
+
assert(self._unsentCount == 0, "Cannot set while unsent values exist")
|
|
50
|
+
|
|
51
|
+
self._maxBatchSize = maxBatchSize
|
|
52
|
+
end
|
|
53
|
+
|
|
44
54
|
--[=[
|
|
45
55
|
@param id number
|
|
46
56
|
@return Promise<T>
|
|
@@ -59,7 +69,7 @@ function Aggregator:Promise(id)
|
|
|
59
69
|
self._unsentCount = self._unsentCount + 1
|
|
60
70
|
self._promisesLruCache:set(id, promise)
|
|
61
71
|
|
|
62
|
-
self:
|
|
72
|
+
self:_queueBatchRequests()
|
|
63
73
|
|
|
64
74
|
return promise
|
|
65
75
|
end
|
|
@@ -76,7 +86,7 @@ function Aggregator:Observe(id)
|
|
|
76
86
|
return Rx.fromPromise(self:Promise(id))
|
|
77
87
|
end
|
|
78
88
|
|
|
79
|
-
function Aggregator:
|
|
89
|
+
function Aggregator:_sendBatchedPromises(promiseMap)
|
|
80
90
|
assert(promiseMap, "No promiseMap")
|
|
81
91
|
|
|
82
92
|
local idList = {}
|
|
@@ -90,9 +100,9 @@ function Aggregator:_sendAggregatedPromises(promiseMap)
|
|
|
90
100
|
return
|
|
91
101
|
end
|
|
92
102
|
|
|
93
|
-
assert(#idList <= self.
|
|
103
|
+
assert(#idList <= self._maxBatchSize, "Too many idList sent")
|
|
94
104
|
|
|
95
|
-
self._maid:GivePromise(self.
|
|
105
|
+
self._maid:GivePromise(self._promiseBatchQuery(idList))
|
|
96
106
|
:Then(function(result)
|
|
97
107
|
assert(type(result) == "table", "Bad result")
|
|
98
108
|
|
|
@@ -107,11 +117,13 @@ function Aggregator:_sendAggregatedPromises(promiseMap)
|
|
|
107
117
|
|
|
108
118
|
-- Reject other ones
|
|
109
119
|
for id, promise in pairs(unresolvedMap) do
|
|
110
|
-
promise:Reject(string.format("
|
|
120
|
+
promise:Reject(string.format("[Aggregator] %s failed to get result for id %d", self._debugName, id))
|
|
111
121
|
end
|
|
112
|
-
end, function(...)
|
|
122
|
+
end, function(err, ...)
|
|
123
|
+
local text = string.format("[Aggregator] %s failed to get bulk result - %q", self._debugName, tostring(err))
|
|
124
|
+
|
|
113
125
|
for _, item in pairs(unresolvedMap) do
|
|
114
|
-
item:Reject(...)
|
|
126
|
+
item:Reject(text, ...)
|
|
115
127
|
end
|
|
116
128
|
end)
|
|
117
129
|
end
|
|
@@ -126,9 +138,9 @@ function Aggregator:_resetQueue()
|
|
|
126
138
|
return promiseMap
|
|
127
139
|
end
|
|
128
140
|
|
|
129
|
-
function Aggregator:
|
|
130
|
-
if self._unsentCount >= self.
|
|
131
|
-
self:
|
|
141
|
+
function Aggregator:_queueBatchRequests()
|
|
142
|
+
if self._unsentCount >= self._maxBatchSize then
|
|
143
|
+
self:_sendBatchedPromises(self:_resetQueue())
|
|
132
144
|
return
|
|
133
145
|
end
|
|
134
146
|
|
|
@@ -138,7 +150,7 @@ function Aggregator:_queueAggregatedPromises()
|
|
|
138
150
|
|
|
139
151
|
self._maid._queue = task.delay(0.1, function()
|
|
140
152
|
task.spawn(function()
|
|
141
|
-
self:
|
|
153
|
+
self:_sendBatchedPromises(self:_resetQueue())
|
|
142
154
|
end)
|
|
143
155
|
end)
|
|
144
156
|
end
|