Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions src/shared/utils/mm-review-summations.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ export function buildStatisticsData(reviewSummations = []) {
if (!summation) {
return false;
}
const score = normalizeScoreValue(_.get(summation, 'aggregateScore'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The normalizeScoreValue function is called multiple times for the same aggregateScore value within the same loop iteration. Consider storing the result in a variable to avoid redundant computations.

if (_.isNil(score)) {
return false;
}
return getSummationScoreClassification(summation).isProvisional;
});

Expand All @@ -587,6 +591,19 @@ export function buildStatisticsData(reviewSummations = []) {
return;
}

const timestamp = getSummationTimestamp(summation);
const timestampValue = toTimestampValue(timestamp);
const score = normalizeScoreValue(_.get(summation, 'aggregateScore'));
if (_.isNil(score)) {
return;
}
const scoreType = getSummationScoreClassification(summation);
if (includeOnlyProvisional) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
The includeOnlyProvisional check is performed inside the loop for each summation. If includeOnlyProvisional is false, this check is unnecessary and could be moved outside the loop to avoid redundant evaluations.

if (!scoreType.isProvisional) {
return;
}
}

const handle = getSummationHandle(summation);
if (!grouped.has(handle)) {
grouped.set(handle, {
Expand All @@ -597,25 +614,11 @@ export function buildStatisticsData(reviewSummations = []) {
}

const entry = grouped.get(handle);

const rating = getSummationRating(summation);
if (_.isNil(entry.rating) && !_.isNil(rating)) {
entry.rating = rating;
}

const timestamp = getSummationTimestamp(summation);
const timestampValue = toTimestampValue(timestamp);
const score = normalizeScoreValue(_.get(summation, 'aggregateScore'));
if (_.isNil(score)) {
return;
}
if (includeOnlyProvisional) {
const scoreType = getSummationScoreClassification(summation);
if (!scoreType.isProvisional) {
return;
}
}

const rawSubmissionId = _.get(
summation,
'submissionId',
Expand Down Expand Up @@ -643,20 +646,22 @@ export function buildStatisticsData(reviewSummations = []) {
entry.submissionsMap.set(submissionId, updatedSubmission);
});

return Array.from(grouped.values()).map(entry => ({
handle: entry.handle,
rating: entry.rating,
submissions: Array.from(entry.submissionsMap.values())
.map(submission => ({
submissionId: submission.submissionId,
created: submission.created,
createdAt: submission.createdAt,
score: submission.score,
}))
.sort(
(a, b) => toTimestampValue(b.createdAt) - toTimestampValue(a.createdAt),
),
}));
return Array.from(grouped.values())
.map(entry => ({
handle: entry.handle,
rating: entry.rating,
submissions: Array.from(entry.submissionsMap.values())
.map(submission => ({
submissionId: submission.submissionId,
created: submission.created,
createdAt: submission.createdAt,
score: submission.score,
}))
.sort(
(a, b) => toTimestampValue(b.createdAt) - toTimestampValue(a.createdAt),
),
}))
.filter(entry => Array.isArray(entry.submissions) && entry.submissions.length > 0);
}

export default {
Expand Down
6 changes: 4 additions & 2 deletions src/shared/utils/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ export function getUnSelectedColors(rating) {
*/
export function getAuthTokens(req = {}) {
const cookies = req.cookies || {};
let tokenV2 = cookies.tcjwt;
let tokenV3 = cookies.tcjwt;
// Support both historical cookie names used across environments.
const authToken = cookies.tcjwt || cookies.tcJwt;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The variable authToken is assigned the value of cookies.tcjwt || cookies.tcJwt. If both tcjwt and tcJwt are present, this will always prefer tcjwt. Ensure this behavior is intentional and aligns with the expected logic for handling these cookies.

let tokenV2 = authToken;
let tokenV3 = authToken;

if (!tokenV2 || isTokenExpired(tokenV2, config.AUTH_DROP_TIME)) {
tokenV2 = '';
Expand Down
Loading