Poprawki wydajności

This commit is contained in:
2022-10-17 16:28:07 +02:00
parent 83aa054a70
commit c395340054
3 changed files with 33 additions and 33 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
index.html,1665605211157,71f3e676d9ddbcafd2a6e4773a9c2a757a0bd51e884f632dbe7351c16b2f9674
logo.svg,1665605133131,6441e7d33cf714ef1cb9dc7fbb816cf2f5340d343ef518f7856619002f1ab48e logo.svg,1665605133131,6441e7d33cf714ef1cb9dc7fbb816cf2f5340d343ef518f7856619002f1ab48e
assets/index.cbb2a49f.css,1665605211157,f02460bf3d64c35cf17b4c9e9c46a7d9d32680d22b006d76bfda4e0abb31b5be index.html,1665943324670,eedf202dd40bfb0b5d15ff62c816e85f3686ec79b5fc832e80a9bc4d6e87b463
assets/index.83548fb0.js,1665605211157,c2fb42de2fa35be75163458fd213617b9c60e168a32bb524d42ff3d7ceb72e25 assets/index.3c31aafa.css,1665943324675,3721eea2e25edd61839ae6acd54ec12bc8a39334ef5698a504f97b0df4e8ee3e
assets/index.d0562efe.js,1665943324675,b22ce921d90c2cd0ff6b197ebf59e5815cd8f645c4fe6625738ef03645b33279
+2 -3
View File
@@ -2,9 +2,8 @@ interface ITableRowValues {
routeTo: string; routeTo: string;
routeVia: string; routeVia: string;
currentRouteToIndex: number; // routeTo, routeVia, date1, date2, date3, date4
currentRouteViaIndex: number; currentRowIndexes: [number, number, number, number, number, number];
currentDateDigitIndex: number;
dateDigits: string[], dateDigits: string[],
} }
+28 -27
View File
@@ -116,7 +116,7 @@ const departureInfoEmptyObj: ITableRow = {
trainNumber: '', trainNumber: '',
date: new Date(0), date: new Date(0),
dateDigits: [' ', ' ', ' ', ' '], dateDigits: ['', '', '', ''],
arrivalTimestamp: 0, arrivalTimestamp: 0,
departureTimestamp: 0, departureTimestamp: 0,
@@ -125,14 +125,12 @@ const departureInfoEmptyObj: ITableRow = {
delayMinutes: 0, delayMinutes: 0,
tableValues: { tableValues: {
routeTo: ' ', routeTo: '',
routeVia: ' ', routeVia: '',
currentRouteToIndex: 0, currentRowIndexes: [0, 0, 0, 0, 0, 0],
currentRouteViaIndex: 0,
currentDateDigitIndex: 0,
dateDigits: [' ', ' ', ' ', ' '], dateDigits: ['', '', '', ''],
}, },
}; };
@@ -153,14 +151,14 @@ export default defineComponent({
apiTrainData: [] as ITrainResponse[], apiTrainData: [] as ITrainResponse[],
animationFrameIndex: 0, isAnimationRunning: true,
intervalIndex: 0, intervalIndex: 0,
lastRefreshTime: 0, lastRefreshTime: 0,
departureTable: new Array(7).fill(0).map(() => ({ ...departureInfoEmptyObj })) as ITableRow[], departureTable: new Array(7).fill(0).map(() => ({ ...departureInfoEmptyObj })) as ITableRow[],
departureRoutes: [''], departureRoutes: [''],
dateDigits: [' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], dateDigits: ['', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
currentRouteIndex: 0, currentRouteIndex: 0,
currentDateDigitIndex: 0, currentDateDigitIndex: 0,
@@ -183,11 +181,13 @@ export default defineComponent({
this.fetchDepartureList(); this.fetchDepartureList();
}, 30000); }, 30000);
this.animationFrameIndex = requestAnimationFrame(this.update); this.isAnimationRunning = true;
requestAnimationFrame(this.update);
}, },
deactivated() { deactivated() {
cancelAnimationFrame(this.animationFrameIndex); this.isAnimationRunning = false;
clearInterval(this.intervalIndex); clearInterval(this.intervalIndex);
}, },
@@ -226,7 +226,7 @@ export default defineComponent({
const date = departureLine ? new Date(departureTimestamp) : new Date(arrivalTimestamp); const date = departureLine ? new Date(departureTimestamp) : new Date(arrivalTimestamp);
// [HH, MM, SS] - nienawidzę dat w JavaScripcie // [HH, MM, SS] - nienawidzę dat w JavaScripcie
const dateArray = date.toLocaleString('pl-PL').split(', ')[1].split(':') || [' ', ' ', ' ', ' ']; const dateArray = date.toLocaleString('pl-PL').split(', ')[1].split(':') || ['', '', '', ''];
// [H,H,M,M] - ZABIJCIE MNIE BŁAGAM // [H,H,M,M] - ZABIJCIE MNIE BŁAGAM
const dateDigits = [...dateArray[0].split(''), ...dateArray[1].split('')]; const dateDigits = [...dateArray[0].split(''), ...dateArray[1].split('')];
@@ -249,10 +249,8 @@ export default defineComponent({
tableValues: { tableValues: {
routeTo: '', routeTo: '',
routeVia: '', routeVia: '',
dateDigits: [' ', ' ', ' ', ' '], dateDigits: ['', '', '', ''],
currentRouteToIndex: 0, currentRowIndexes: [0, 0, 0, 0, 0, 0],
currentRouteViaIndex: 0,
currentDateDigitIndex: 0,
}, },
}); });
@@ -288,7 +286,7 @@ export default defineComponent({
trainNumber: '', trainNumber: '',
date: new Date(0), date: new Date(0),
dateDigits: [' ', ' ', ' ', ' '], dateDigits: ['', '', '', ''],
arrivalTimestamp: 0, arrivalTimestamp: 0,
departureTimestamp: 0, departureTimestamp: 0,
@@ -326,6 +324,8 @@ export default defineComponent({
}, },
update(time: number) { update(time: number) {
if (!this.isAnimationRunning) return;
if (time >= this.lastRefreshTime + 125) { if (time >= this.lastRefreshTime + 125) {
this.updateTableRows(); this.updateTableRows();
@@ -342,25 +342,26 @@ export default defineComponent({
updateTableRows() { updateTableRows() {
this.departureTable.forEach((dep, i) => { this.departureTable.forEach((dep, i) => {
if (dep.tableValues.routeTo.toLowerCase() != dep.routeTo.toLowerCase()) { if (dep.tableValues.routeTo.toLowerCase() != dep.routeTo.toLowerCase()) {
dep.tableValues.routeTo = this.departureRoutes[dep.tableValues.currentRouteToIndex]; dep.tableValues.routeTo = this.departureRoutes[dep.tableValues.currentRowIndexes[0]];
dep.tableValues.currentRouteToIndex = (dep.tableValues.currentRouteToIndex + 1) % this.departureRoutes.length; dep.tableValues.currentRowIndexes[0] =
(dep.tableValues.currentRowIndexes[0] + 1) % this.departureRoutes.length;
} }
if (dep.tableValues.routeVia.toLowerCase() != dep.routeVia.toLowerCase()) { if (dep.tableValues.routeVia.toLowerCase() != dep.routeVia.toLowerCase()) {
dep.tableValues.routeVia = this.departureRoutes[dep.tableValues.currentRouteViaIndex]; dep.tableValues.routeVia = this.departureRoutes[dep.tableValues.currentRowIndexes[1]];
dep.tableValues.currentRouteViaIndex = dep.tableValues.currentRowIndexes[1] =
(dep.tableValues.currentRouteViaIndex + 1) % this.departureRoutes.length; (dep.tableValues.currentRowIndexes[1] + 1) % this.departureRoutes.length;
} }
dep.tableValues.dateDigits.forEach((digit, j) => { dep.tableValues.dateDigits.forEach((digit, j) => {
if (dep.dateDigits[j] != digit) if (dep.dateDigits[j] != digit) {
dep.tableValues.dateDigits[j] = this.dateDigits[dep.tableValues.currentDateDigitIndex]; dep.tableValues.dateDigits[j] = this.dateDigits[dep.tableValues.currentRowIndexes[j + 2]];
dep.tableValues.currentRowIndexes[j + 2] =
(dep.tableValues.currentRowIndexes[j + 2] + 1) % this.dateDigits.length;
}
}); });
// Poprawić do wszystkich
dep.tableValues.currentDateDigitIndex = (dep.tableValues.currentDateDigitIndex + 1) % this.dateDigits.length;
}); });
}, },