shuttlepro-shared 1.2.34 → 1.2.35
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { UserRole } = require("../../models/UserRole");
|
|
2
2
|
const {
|
|
3
3
|
getDataFromRedisSet,
|
|
4
|
-
|
|
4
|
+
addArrayToRedisSet,
|
|
5
5
|
} = require("../../config/redis");
|
|
6
6
|
|
|
7
7
|
const defaultSelect =
|
|
@@ -13,7 +13,7 @@ const CACHE_KEY_USER_WORKSPACE_PREFIX = "userrole_workspace_";
|
|
|
13
13
|
|
|
14
14
|
// Clear user workspace cache
|
|
15
15
|
const clearUserWorkspaceCache = async (userId) => {
|
|
16
|
-
await
|
|
16
|
+
await addArrayToRedisSet(`${CACHE_KEY_USER_WORKSPACE_PREFIX}${userId}`, null);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// Get cached members
|
|
@@ -41,7 +41,7 @@ const getCachedMembers = async (filter = {}) => {
|
|
|
41
41
|
.lean()
|
|
42
42
|
.exec();
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await addArrayToRedisSet(cacheKey, members);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return members;
|
|
@@ -69,7 +69,7 @@ const updateCachedMembers = async (filter = {}) => {
|
|
|
69
69
|
.lean()
|
|
70
70
|
.exec();
|
|
71
71
|
|
|
72
|
-
await
|
|
72
|
+
await addArrayToRedisSet(cacheKey, members);
|
|
73
73
|
return members;
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -141,9 +141,9 @@ const findUserWorkspaces = async (userId) => {
|
|
|
141
141
|
})
|
|
142
142
|
.lean()
|
|
143
143
|
.exec();
|
|
144
|
-
console.log(userRoleWithWorkspaces, "
|
|
144
|
+
console.log(userRoleWithWorkspaces, "through db");
|
|
145
145
|
if (userRoleWithWorkspaces) {
|
|
146
|
-
await
|
|
146
|
+
await addArrayToRedisSet(cacheKey, userRoleWithWorkspaces);
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
return userRoleWithWorkspaces;
|
package/config/redis.js
CHANGED
|
@@ -103,14 +103,30 @@ const addDataToRedisSet = async (key, value) => {
|
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
|
+
|
|
107
|
+
const addArrayToRedisSet = async (key, value) => {
|
|
108
|
+
try {
|
|
109
|
+
await connectRedis();
|
|
110
|
+
console.log(key, "key");
|
|
111
|
+
const arr = Array.isArray(value) ? value : [value];
|
|
112
|
+
console.log(arr, "arr");
|
|
113
|
+
await client.sAdd(key, ...arr); // spread values
|
|
114
|
+
return true;
|
|
115
|
+
} catch (err) {
|
|
116
|
+
console.error("Add Error:", err);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
106
121
|
const getDataFromRedisSet = async (key) => {
|
|
107
122
|
try {
|
|
108
123
|
await connectRedis();
|
|
124
|
+
console.log(key, "key");
|
|
109
125
|
const values = await client.sMembers(key);
|
|
110
126
|
console.log(values, "values");
|
|
111
|
-
return values;
|
|
127
|
+
return values;
|
|
112
128
|
} catch (err) {
|
|
113
|
-
console.error("
|
|
129
|
+
console.error("Get Error:", err);
|
|
114
130
|
return [];
|
|
115
131
|
}
|
|
116
132
|
};
|
|
@@ -200,4 +216,5 @@ module.exports = {
|
|
|
200
216
|
removeDataFromRedisSet,
|
|
201
217
|
isMemberOfRedisSet,
|
|
202
218
|
getDataFromRedisSet,
|
|
219
|
+
addArrayToRedisSet,
|
|
203
220
|
};
|