Skip to content

Commit aada0f8

Browse files
authored
Merge pull request #2506 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents 8b53aae + 7732c90 commit aada0f8

26 files changed

+349
-1025
lines changed

config/custom-environment-variables.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ module.exports = {
126126
},
127127
},
128128

129-
routesCacheTTL: {
130-
"/members": "ROUTESCACHETTL_MEMBERS",
131-
},
129+
routesCacheTTL: {},
132130

133131
Event100ms: {
134132
APP_ACCESS_KEY: "EVENT_100MS_APP_ACCESS_KEY",

config/default.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ module.exports = {
130130
},
131131
},
132132

133-
routesCacheTTL: {
134-
"/members": 900,
135-
},
133+
routesCacheTTL: {},
136134

137135
Event100ms: {
138136
APP_ACCESS_KEY: "EVENT_100MS_APP_ACCESS_KEY",

constants/userStatus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export const statusState = {
1212
};
1313

1414
export const CANCEL_OOO = "cancelOoo";
15+
16+
export const POST_OOO_GRACE_PERIOD_IN_DAYS = 3;

controllers/members.js

Lines changed: 0 additions & 122 deletions
This file was deleted.

controllers/recruiters.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

controllers/users.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {
3131
USERS_PATCH_HANDLER_SUCCESS_MESSAGES,
3232
} = require("../constants/users");
3333
const { addLog } = require("../models/logs");
34-
const { getUserStatus } = require("../models/userStatus");
34+
const { getUserStatus, runLastOooUntilMigration } = require("../models/userStatus");
3535
const config = require("config");
3636
const { generateUniqueUsername } = require("../services/users");
3737
const userService = require("../services/users");
@@ -80,6 +80,19 @@ const getUserById = async (req, res) => {
8080
});
8181
};
8282

83+
const updateLastOooUntil = async (req, res) => {
84+
try {
85+
const summary = await runLastOooUntilMigration();
86+
return res.status(200).json({
87+
message: "lastOooUntil migration executed successfully",
88+
data: summary,
89+
});
90+
} catch (error) {
91+
logger.error(`Error while running lastOooUntil migration: ${error}`);
92+
return res.boom.badImplementation(INTERNAL_SERVER_ERROR);
93+
}
94+
};
95+
8396
/**
8497
* Fetches the data about our users
8598
*
@@ -1185,5 +1198,6 @@ module.exports = {
11851198
isDeveloper,
11861199
getIdentityStats,
11871200
updateUsernames,
1201+
updateLastOooUntil,
11881202
updateProfile,
11891203
};

middlewares/validators/members.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

middlewares/validators/recruiter.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

models/discordactions.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const { findSubscribedGroupIds } = require("../utils/helper");
88
const { retrieveUsers } = require("../services/dataAccessLayer");
99
const { BATCH_SIZE_IN_CLAUSE } = require("../constants/firebase");
1010
const { getAllUserStatus, getGroupRole, getUserStatus } = require("./userStatus");
11-
const { userState } = require("../constants/userStatus");
11+
const { normalizeTimestamp } = require("../utils/userStatus");
12+
const { userState, POST_OOO_GRACE_PERIOD_IN_DAYS } = require("../constants/userStatus");
1213
const { ONE_DAY_IN_MS, SIMULTANEOUS_WORKER_CALLS } = require("../constants/users");
1314
const userModel = firestore.collection("users");
1415
const photoVerificationModel = firestore.collection("photo-verification");
@@ -958,6 +959,7 @@ const getMissedProgressUpdatesUsers = async (options = {}) => {
958959
const stats = {
959960
tasks: 0,
960961
missedUpdatesTasks: 0,
962+
filteredByOoo: 0,
961963
};
962964
try {
963965
const discordUsersPromise = discordService.getDiscordMembers();
@@ -1031,8 +1033,7 @@ const getMissedProgressUpdatesUsers = async (options = {}) => {
10311033

10321034
const userIdChunks = chunks(Array.from(usersMap.keys()), FIRESTORE_IN_CLAUSE_SIZE);
10331035
const userStatusSnapshotPromise = userIdChunks.map(
1034-
async (userIdList) =>
1035-
await userStatusModel.where("currentStatus.state", "==", userState.OOO).where("userId", "in", userIdList).get()
1036+
async (userIdList) => await userStatusModel.where("userId", "in", userIdList).get()
10361037
);
10371038
const userDetailsPromise = userIdChunks.map(
10381039
async (userIdList) =>
@@ -1046,7 +1047,13 @@ const getMissedProgressUpdatesUsers = async (options = {}) => {
10461047

10471048
userStatusChunks.forEach((userStatusList) =>
10481049
userStatusList.forEach((doc) => {
1049-
usersMap.get(doc.data().userId).isOOO = true;
1050+
const userStatusData = doc.data();
1051+
const mappedUser = usersMap.get(userStatusData.userId);
1052+
if (!mappedUser) {
1053+
return;
1054+
}
1055+
mappedUser.isOOO = userStatusData.currentStatus?.state === userState.OOO;
1056+
mappedUser.lastOooUntil = userStatusData.lastOooUntil ?? null;
10501057
})
10511058
);
10521059

@@ -1083,9 +1090,18 @@ const getMissedProgressUpdatesUsers = async (options = {}) => {
10831090

10841091
await Promise.all(progressCountPromise);
10851092

1093+
const gracePeriodCutoff = Date.now() - convertDaysToMilliseconds(POST_OOO_GRACE_PERIOD_IN_DAYS);
10861094
for (const [userId, userData] of usersMap.entries()) {
10871095
const discordUserData = discordUserMap.get(userData.discordId);
10881096
const isDiscordMember = !!discordUserData;
1097+
const normalizedLastOooUntil = normalizeTimestamp(userData.lastOooUntil);
1098+
const isWithinGracePeriod = normalizedLastOooUntil !== null && normalizedLastOooUntil >= gracePeriodCutoff;
1099+
1100+
if (userData.latestProgressCount === 0 && (userData.isOOO || isWithinGracePeriod)) {
1101+
stats.filteredByOoo++;
1102+
usersMap.delete(userId);
1103+
continue;
1104+
}
10891105
const shouldAddRole =
10901106
userData.latestProgressCount === 0 &&
10911107
!userData.isOOO &&

0 commit comments

Comments
 (0)