Skip to content

Commit

Permalink
Issue #232165 fix: Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravmore committed Dec 22, 2024
1 parent 06257e6 commit 958c4ef
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/all-dev-tn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ALL tn dev Deployment
on:
push:
branches:
- all-1.2-tn-dev
- release-1.3-apicall-optimisation

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lerna-debug.log*
.env
#build
build

*.env*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
16 changes: 15 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FingerprintJS from "@fingerprintjs/fingerprintjs";
import routes from "./routes";
import { AppContent } from "./views";
import theme from "./assets/styles/theme";
import { initialize } from "./services/telementryService";
import { initialize, end } from "./services/telementryService";
import { startEvent } from "./services/callTelemetryIntract";
import "@project-sunbird/telemetry-sdk/index.js";
import { getParameter } from "./utils/constants";
Expand Down Expand Up @@ -72,6 +72,20 @@ const App = () => {
setFp();
}, []);

useEffect(() => {
const handleBeforeUnload = (event) => {
window.telemetry && window.telemetry.syncEvents && window.telemetry.syncEvents();
};

// Add the event listener
window.addEventListener("beforeunload", handleBeforeUnload);

// Cleanup the event listener on component unmount
return () => {
window.removeEventListener("beforeunload", handleBeforeUnload);
};
}, []);

useEffect(() => {
let virtualId;

Expand Down
12 changes: 7 additions & 5 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,12 @@ const Assesment = ({ discoverStart }) => {
}

localStorage.setItem("lang", lang || "ta");
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${usernameDetails?.data?.result?.virtualID}/${session_id}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${usernameDetails?.data?.result?.virtualID}/${session_id}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}

dispatch(setVirtualId(usernameDetails?.data?.result?.virtualID));
})();
Expand Down Expand Up @@ -635,7 +637,7 @@ const Assesment = ({ discoverStart }) => {
localStorage.setItem("sessionId", sessionId);
}

if (virtualId) {
if (virtualId && localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
Expand Down
11 changes: 7 additions & 4 deletions src/components/AssesmentEnd/AssesmentEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ const AssesmentEnd = () => {
sessionId = uniqueId();
localStorage.setItem("sessionId", sessionId)
}
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);

if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}
})();
setTimeout(() => {
setShake(false);
Expand Down
59 changes: 30 additions & 29 deletions src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,18 @@ const SpeakSentenceComponent = () => {
try {
const lang = getLocalData("lang");

if (!(localStorage.getItem("contentSessionId") !== null)) {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: "m0",
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
} else {
send(1);
// setPoints(localStorage.getItem("currentLessonScoreCount"));
}

await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
milestone: `discoveryList/discovery/${currentCollectionId}`,
lesson: localStorage.getItem("storyTitle"),
progress: ((currentQuestion + 1) * 100) / questions.length,
language: lang,
milestoneLevel: "m0",
}
);
// await axios.post(
// `${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
// {
// userId: localStorage.getItem("virtualId"),
// sessionId: localStorage.getItem("sessionId"),
// milestone: `discoveryList/discovery/${currentCollectionId}`,
// lesson: localStorage.getItem("storyTitle"),
// progress: ((currentQuestion + 1) * 100) / questions.length,
// language: lang,
// milestoneLevel: "m0",
// }
// );

if (currentQuestion < questions.length - 1) {
setCurrentQuestion(currentQuestion + 1);
Expand All @@ -164,6 +147,24 @@ const SpeakSentenceComponent = () => {
language: localStorage.getItem("lang"),
}
);

if (!(localStorage.getItem("contentSessionId") !== null)) {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: "m0",
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
} else {
send(5);
// setPoints(localStorage.getItem("currentLessonScoreCount"));
}

setInitialAssesment(false);
const { data: getSetData } = getSetResultRes;
const data = JSON.stringify(getSetData?.data);
Expand Down
27 changes: 18 additions & 9 deletions src/services/telementryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CsTelemetryModule } from '@project-sunbird/client-services/telemetry';
import { uniqueId } from './utilService';
import { jwtDecode } from '../../node_modules/jwt-decode/build/cjs/index';

let startTime; // Variable to store the timestamp when the start event is raised
let contentSessionId;
let playSessionId;
let url;
Expand Down Expand Up @@ -65,6 +66,7 @@ export const initialize = async ({ context, config, metadata }) => {

export const start = (duration) => {
try {
startTime = Date.now(); // Record the start time
CsTelemetryModule.instance.telemetryService.raiseStartTelemetry({
options: getEventOptions(),
edata: {
Expand Down Expand Up @@ -114,15 +116,22 @@ export const Log = (context, pageid, telemetryMode) => {
};

export const end = (data) => {
CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: url,
summary: data?.summary || {},
duration: data?.duration || '000',
},
});
try {
const endTime = Date.now(); // Record the end time
const duration = ((endTime - startTime) / 1000).toFixed(2); // Calculate duration in seconds

CsTelemetryModule.instance.telemetryService.raiseEndTelemetry({
edata: {
type: 'content',
mode: 'play',
pageid: url,
summary: data?.summary || {},
duration: duration, // Log the calculated duration
},
});
} catch (error) {
console.error("Error in end telemetry event:", error);
}
};

export const interact = (telemetryMode) => {
Expand Down
75 changes: 40 additions & 35 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,6 @@ const Practice = () => {

try {
const lang = getLocalData("lang");
if (localStorage.getItem("contentSessionId") !== null) {
setPoints(1);
if (isShowCase) {
send(1);
}
} else {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: `m${level}`,
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
}

const virtualId = getLocalData("virtualId");
const sessionId = getLocalData("sessionId");
Expand All @@ -217,18 +199,18 @@ const Practice = () => {

let showcasePercentage = ((currentQuestion + 1) * 100) / questions.length;

await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
userId: virtualId,
sessionId: sessionId,
milestone: isShowCase ? "showcase" : `practice`,
lesson: currentPracticeStep,
progress: isShowCase ? showcasePercentage : currentPracticeProgress,
language: lang,
milestoneLevel: `m${level}`,
}
);
// await axios.post(
// `${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
// {
// userId: virtualId,
// sessionId: sessionId,
// milestone: isShowCase ? "showcase" : `practice`,
// lesson: currentPracticeStep,
// progress: isShowCase ? showcasePercentage : currentPracticeProgress,
// language: lang,
// milestoneLevel: `m${level}`,
// }
// );

let newPracticeStep =
currentQuestion === questions.length - 1 || isGameOver
Expand All @@ -245,6 +227,27 @@ const Practice = () => {
);

if (currentQuestion === questions.length - 1 || isGameOver) {

// Set points
if (localStorage.getItem("contentSessionId") !== null) {
setPoints(1);
if (isShowCase) {
send(5);
}
} else {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: `m${level}`,
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
}

// navigate or setNextPracticeLevel
let currentPracticeStep =
practiceProgress[virtualId].currentPracticeStep;
Expand Down Expand Up @@ -471,12 +474,14 @@ const Practice = () => {

// TODO: Handle Error for lessons - no lesson progress - starting point should be P1

const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);
if (localStorage.getItem("contentSessionId") !== null) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
);

// TODO: Just Opss icon - we are trying to fetch the score for you
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
// TODO: Just Opss icon - we are trying to fetch the score for you
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}

let userState = Number.isInteger(
Number(resLessons.data?.result?.result?.lesson)
Expand Down

0 comments on commit 958c4ef

Please sign in to comment.