@quenty/userserviceutils 3.11.0 → 3.11.1-canary.417.052e8ba.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
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
|
+
## [3.11.1-canary.417.052e8ba.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/userserviceutils@3.11.0...@quenty/userserviceutils@3.11.1-canary.417.052e8ba.0) (2023-10-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* User information de-duplication occurs ([bcb5c2a](https://github.com/Quenty/NevermoreEngine/commit/bcb5c2a062fa775e6c0949f2f56f7026456f849a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [3.11.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/userserviceutils@3.10.0...@quenty/userserviceutils@3.11.0) (2023-09-21)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/userserviceutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/userserviceutils",
|
|
3
|
-
"version": "3.11.0",
|
|
3
|
+
"version": "3.11.1-canary.417.052e8ba.0",
|
|
4
4
|
"description": "Utilities involving UserService in Roblox",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/baseobject": "
|
|
29
|
-
"@quenty/loader": "
|
|
30
|
-
"@quenty/maid": "
|
|
31
|
-
"@quenty/math": "
|
|
32
|
-
"@quenty/promise": "
|
|
33
|
-
"@quenty/rx": "
|
|
34
|
-
"@quenty/servicebag": "
|
|
28
|
+
"@quenty/baseobject": "6.3.1-canary.417.052e8ba.0",
|
|
29
|
+
"@quenty/loader": "6.3.1-canary.417.052e8ba.0",
|
|
30
|
+
"@quenty/maid": "2.6.0",
|
|
31
|
+
"@quenty/math": "2.5.0",
|
|
32
|
+
"@quenty/promise": "6.8.1-canary.417.052e8ba.0",
|
|
33
|
+
"@quenty/rx": "7.16.1-canary.417.052e8ba.0",
|
|
34
|
+
"@quenty/servicebag": "6.9.1-canary.417.052e8ba.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "052e8ba33437f71398c4c08c8dbcbf076022d388"
|
|
40
40
|
}
|
|
@@ -46,6 +46,18 @@ function UserInfoServiceClient:PromiseDisplayName(userId)
|
|
|
46
46
|
return self._aggregator:PromiseDisplayName(userId)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
--[=[
|
|
50
|
+
Observes the user info for the user
|
|
51
|
+
|
|
52
|
+
@param userId number
|
|
53
|
+
@return Observable<UserInfo>
|
|
54
|
+
]=]
|
|
55
|
+
function UserInfoServiceClient:ObserveUserInfo(userId)
|
|
56
|
+
assert(type(userId) == "number", "Bad userId")
|
|
57
|
+
|
|
58
|
+
return self._aggregator:ObserveDisplayName(userId)
|
|
59
|
+
end
|
|
60
|
+
|
|
49
61
|
--[=[
|
|
50
62
|
Observes the user display name for the userId
|
|
51
63
|
|
|
@@ -34,6 +34,18 @@ function UserInfoService:PromiseUserInfo(userId)
|
|
|
34
34
|
return self._aggregator:PromiseUserInfo(userId)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
--[=[
|
|
38
|
+
Observes the user info for the user
|
|
39
|
+
|
|
40
|
+
@param userId number
|
|
41
|
+
@return Observable<UserInfo>
|
|
42
|
+
]=]
|
|
43
|
+
function UserInfoService:ObserveUserInfo(userId)
|
|
44
|
+
assert(type(userId) == "number", "Bad userId")
|
|
45
|
+
|
|
46
|
+
return self._aggregator:ObserveDisplayName(userId)
|
|
47
|
+
end
|
|
48
|
+
|
|
37
49
|
--[=[
|
|
38
50
|
Promises the user display name for the userId
|
|
39
51
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
--[=[
|
|
2
|
-
Aggregates all requests into one big send request
|
|
2
|
+
Aggregates all requests into one big send request to deduplicate the request
|
|
3
3
|
|
|
4
4
|
@class UserInfoAggregator
|
|
5
5
|
]=]
|
|
@@ -11,6 +11,8 @@ local Promise = require("Promise")
|
|
|
11
11
|
local UserServiceUtils = require("UserServiceUtils")
|
|
12
12
|
local Rx = require("Rx")
|
|
13
13
|
|
|
14
|
+
local MAX_USER_IDS_PER_REQUEST = 200
|
|
15
|
+
|
|
14
16
|
local UserInfoAggregator = setmetatable({}, BaseObject)
|
|
15
17
|
UserInfoAggregator.ClassName = "UserInfoAggregator"
|
|
16
18
|
UserInfoAggregator.__index = UserInfoAggregator
|
|
@@ -20,6 +22,8 @@ function UserInfoAggregator.new()
|
|
|
20
22
|
|
|
21
23
|
-- TODO: LRU cache this? Limit to 1k or something?
|
|
22
24
|
self._promises = {}
|
|
25
|
+
|
|
26
|
+
self._unsentCount = 0
|
|
23
27
|
self._unsentPromises = {}
|
|
24
28
|
|
|
25
29
|
return self
|
|
@@ -42,6 +46,7 @@ function UserInfoAggregator:PromiseUserInfo(userId)
|
|
|
42
46
|
local promise = Promise.new()
|
|
43
47
|
|
|
44
48
|
self._unsentPromises[userId] = promise
|
|
49
|
+
self._unsentCount = self._unsentCount + 1
|
|
45
50
|
self._promises[userId] = promise
|
|
46
51
|
|
|
47
52
|
self:_queueAggregatedPromises()
|
|
@@ -64,6 +69,48 @@ function UserInfoAggregator:PromiseDisplayName(userId)
|
|
|
64
69
|
end)
|
|
65
70
|
end
|
|
66
71
|
|
|
72
|
+
--[=[
|
|
73
|
+
Promises the user display name for the userId
|
|
74
|
+
|
|
75
|
+
@param userId number
|
|
76
|
+
@return Promise<string>
|
|
77
|
+
]=]
|
|
78
|
+
function UserInfoAggregator:PromiseDisplayName(userId)
|
|
79
|
+
assert(type(userId) == "number", "Bad userId")
|
|
80
|
+
|
|
81
|
+
return self:PromiseUserInfo(userId)
|
|
82
|
+
:Then(function(userInfo)
|
|
83
|
+
return userInfo.DisplayName
|
|
84
|
+
end)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
--[=[
|
|
88
|
+
Promises the user display name for the userId
|
|
89
|
+
|
|
90
|
+
@param userId number
|
|
91
|
+
@return Promise<boolean>
|
|
92
|
+
]=]
|
|
93
|
+
function UserInfoAggregator:PromiseHasVerifiedBadge(userId)
|
|
94
|
+
assert(type(userId) == "number", "Bad userId")
|
|
95
|
+
|
|
96
|
+
return self:PromiseUserInfo(userId)
|
|
97
|
+
:Then(function(userInfo)
|
|
98
|
+
return userInfo.HasVerifiedBadge
|
|
99
|
+
end)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
--[=[
|
|
103
|
+
Observes the user display name for the userId
|
|
104
|
+
|
|
105
|
+
@param userId number
|
|
106
|
+
@return Observable<UserInfo>
|
|
107
|
+
]=]
|
|
108
|
+
function UserInfoAggregator:ObserveUserInfo(userId)
|
|
109
|
+
assert(type(userId) == "number", "Bad userId")
|
|
110
|
+
|
|
111
|
+
return Rx.fromPromise(self:PromiseUserInfo(userId))
|
|
112
|
+
end
|
|
113
|
+
|
|
67
114
|
--[=[
|
|
68
115
|
Observes the user display name for the userId
|
|
69
116
|
|
|
@@ -73,12 +120,15 @@ end
|
|
|
73
120
|
function UserInfoAggregator:ObserveDisplayName(userId)
|
|
74
121
|
assert(type(userId) == "number", "Bad userId")
|
|
75
122
|
|
|
76
|
-
return
|
|
123
|
+
return self:ObserveUserInfo():Pipe({
|
|
124
|
+
Rx.map(function(userInfo)
|
|
125
|
+
return userInfo.DisplayName
|
|
126
|
+
end)
|
|
127
|
+
})
|
|
77
128
|
end
|
|
78
129
|
|
|
79
|
-
function UserInfoAggregator:_sendAggregatedPromises()
|
|
80
|
-
|
|
81
|
-
self._unsentPromises = {}
|
|
130
|
+
function UserInfoAggregator:_sendAggregatedPromises(promiseMap)
|
|
131
|
+
assert(promiseMap, "No promiseMap")
|
|
82
132
|
|
|
83
133
|
local userIds = {}
|
|
84
134
|
local unresolvedMap = {}
|
|
@@ -91,6 +141,8 @@ function UserInfoAggregator:_sendAggregatedPromises()
|
|
|
91
141
|
return
|
|
92
142
|
end
|
|
93
143
|
|
|
144
|
+
assert(#userIds <= MAX_USER_IDS_PER_REQUEST, "Too many userIds sent")
|
|
145
|
+
|
|
94
146
|
self._maid:GivePromise(UserServiceUtils.promiseUserInfosByUserIds(userIds))
|
|
95
147
|
:Then(function(result)
|
|
96
148
|
assert(type(result) == "table", "Bad result")
|
|
@@ -109,24 +161,37 @@ function UserInfoAggregator:_sendAggregatedPromises()
|
|
|
109
161
|
promise:Reject(string.format("Failed to get result for userId %d", userId))
|
|
110
162
|
end
|
|
111
163
|
end, function(...)
|
|
112
|
-
for _, item in pairs(
|
|
164
|
+
for _, item in pairs(unresolvedMap) do
|
|
113
165
|
item:Reject(...)
|
|
114
166
|
end
|
|
115
167
|
end)
|
|
116
168
|
end
|
|
117
169
|
|
|
170
|
+
function UserInfoAggregator:_resetQueue()
|
|
171
|
+
local promiseMap = self._unsentPromises
|
|
172
|
+
|
|
173
|
+
self._maid._queue = nil
|
|
174
|
+
self._unsentCount = 0
|
|
175
|
+
self._unsentPromises = {}
|
|
176
|
+
|
|
177
|
+
return promiseMap
|
|
178
|
+
end
|
|
179
|
+
|
|
118
180
|
function UserInfoAggregator:_queueAggregatedPromises()
|
|
119
|
-
if self.
|
|
181
|
+
if self._unsentCount >= MAX_USER_IDS_PER_REQUEST then
|
|
182
|
+
self:_sendAggregatedPromises(self:_resetQueue())
|
|
183
|
+
return
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
if self._maid._queue then
|
|
120
187
|
return
|
|
121
188
|
end
|
|
122
189
|
|
|
123
|
-
self.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
190
|
+
self._maid._queue = task.delay(0.1, function()
|
|
191
|
+
task.spawn(function()
|
|
192
|
+
self:_sendAggregatedPromises(self:_resetQueue())
|
|
193
|
+
end)
|
|
127
194
|
end)
|
|
128
195
|
end
|
|
129
196
|
|
|
130
|
-
|
|
131
|
-
|
|
132
197
|
return UserInfoAggregator
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
--[=[
|
|
2
|
+
Wraps [UserService] API calls with [Promise].
|
|
3
|
+
|
|
2
4
|
@class UserServiceUtils
|
|
3
5
|
]=]
|
|
4
6
|
|
|
@@ -15,11 +17,17 @@ local UserServiceUtils = {}
|
|
|
15
17
|
.Id number -- The Id associated with the UserInfoResponse object
|
|
16
18
|
.Username string -- The username associated with the UserInfoResponse object
|
|
17
19
|
.DisplayName string -- The display name associated with the UserInfoResponse object
|
|
20
|
+
.HasVerifiedBadge boolean -- The HasVerifiedBadge value associated with the user.
|
|
18
21
|
@within UserServiceUtils
|
|
19
22
|
]=]
|
|
20
23
|
|
|
21
24
|
--[=[
|
|
22
25
|
Wraps UserService:GetUserInfosByUserIdsAsync(userIds)
|
|
26
|
+
|
|
27
|
+
::: tip
|
|
28
|
+
User [UserInfoAggregator] via [UserInfoService] to get this deduplicated.
|
|
29
|
+
:::
|
|
30
|
+
|
|
23
31
|
@param userIds { number }
|
|
24
32
|
@return Promise<{ UserInfo }>
|
|
25
33
|
]=]
|
|
@@ -46,6 +54,10 @@ end
|
|
|
46
54
|
--[=[
|
|
47
55
|
Wraps UserService:GetUserInfosByUserIdsAsync({ userId })[1]
|
|
48
56
|
|
|
57
|
+
::: tip
|
|
58
|
+
User [UserInfoAggregator] via [UserInfoService] to get this deduplicated.
|
|
59
|
+
:::
|
|
60
|
+
|
|
49
61
|
@param userId number
|
|
50
62
|
@return Promise<UserInfo>
|
|
51
63
|
]=]
|
|
@@ -67,6 +79,10 @@ end
|
|
|
67
79
|
--[=[
|
|
68
80
|
Wraps UserService:GetUserInfosByUserIdsAsync({ userId })[1].DisplayName
|
|
69
81
|
|
|
82
|
+
::: tip
|
|
83
|
+
User [UserInfoAggregator] via [UserInfoService] to get this deduplicated.
|
|
84
|
+
:::
|
|
85
|
+
|
|
70
86
|
@param userId number
|
|
71
87
|
@return Promise<string>
|
|
72
88
|
]=]
|
|
@@ -82,6 +98,10 @@ end
|
|
|
82
98
|
--[=[
|
|
83
99
|
Wraps UserService:GetUserInfosByUserIdsAsync({ userId })[1].Username
|
|
84
100
|
|
|
101
|
+
::: tip
|
|
102
|
+
User [UserInfoAggregator] via [UserInfoService] to get this deduplicated.
|
|
103
|
+
:::
|
|
104
|
+
|
|
85
105
|
@param userId number
|
|
86
106
|
@return Promise<string>
|
|
87
107
|
]=]
|