Skip to content

Commit ec095f7

Browse files
authored
Merge pull request #119 from buggregator/hotifx/performance
Code optimization
2 parents 25b9782 + 9306b4b commit ec095f7

File tree

4 files changed

+28
-49
lines changed

4 files changed

+28
-49
lines changed

src/entities/sentry/ui/sentry-exception/sentry-exception.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ const exceptionFrames = computed(() => {
1616
const frames = props.exception.stacktrace.frames || [];
1717
1818
if (props.maxFrames > 0) {
19-
return frames.slice(0, props.maxFrames);
19+
return frames.slice(0 - props.maxFrames).reverse();
2020
}
2121
22-
return [...frames].reverse();
22+
return frames.slice().reverse();
2323
});
2424
</script>
2525

src/shared/lib/use-api-transport/use-api-transport.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ export const useApiTransport = () => {
2424
} = useEventsRequests()
2525

2626
const getWSConnection = () => connectionStore.isConnectedWS
27-
const checkWSConnectionFail = (onConnectionLost: () => void) => {
28-
if (!getWSConnection()) {
29-
onConnectionLost()
30-
}
31-
setTimeout(() => {
32-
checkWSConnectionFail(onConnectionLost)
33-
}, CHECK_CONNECTION_INTERVAL)
34-
}
27+
// todo: move to useCentrifuge
28+
// const checkWSConnectionFail = (onConnectionLost: () => void) => {
29+
// if (!getWSConnection()) {
30+
// onConnectionLost()
31+
// }
32+
// setTimeout(() => {
33+
// checkWSConnectionFail(onConnectionLost)
34+
// }, CHECK_CONNECTION_INTERVAL)
35+
// }
3536

3637
const subscribeToEvents = (): void => {
3738
centrifuge.on('connected', () => {
@@ -64,10 +65,12 @@ export const useApiTransport = () => {
6465
isEventsEmitted = true
6566
}
6667

67-
checkWSConnectionFail(async () => {
68-
const events = await getAll();
69-
eventsStore.addList(events);
70-
})
68+
// todo: move to useCentrifuge
69+
// checkWSConnectionFail(async () => {
70+
// const events = await getAll();
71+
//
72+
// eventsStore.addList(events);
73+
// })
7174

7275
const deleteEvent = (eventId: EventId) => {
7376
if (getWSConnection()) {

src/shared/ui/preview-card/preview-card.vue

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// TODO: move component out of shared/ui
33
import download from "downloadjs";
44
import { toBlob, toPng } from "html-to-image";
5-
import debounce from "lodash.debounce";
65
import moment from "moment";
7-
import { ref, computed, onMounted, onBeforeUnmount, onBeforeMount } from "vue";
6+
import { ref, computed, onBeforeMount } from "vue";
87
import { REST_API_URL } from "../../lib/io";
98
import { useEvents } from "../../lib/use-events";
109
import type { NormalizedEvent } from "../../types";
@@ -123,37 +122,9 @@ const copyCode = () => {
123122
}
124123
};
125124
126-
const optimiseRenderHidden = debounce(() => {
127-
if (eventRef.value) {
128-
const eventNode = eventRef.value as HTMLElement;
129-
const { top, height } = eventNode.getBoundingClientRect();
130-
131-
const extraDelta = height;
132-
const isVisible =
133-
top - extraDelta <= window.innerHeight &&
134-
top + height + extraDelta * 2 >= 0;
135-
136-
if (!isVisible && !isOptimized.value) {
137-
isOptimized.value = true;
138-
eventNode.style.height = `${eventNode.clientHeight}px`;
139-
} else if (isVisible && isOptimized.value) {
140-
isOptimized.value = false;
141-
eventNode.style.height = "auto";
142-
}
143-
}
144-
}, 30);
145-
146125
onBeforeMount(() => {
147126
isLocked.value = lockedIds.items.value.includes(props.event.id);
148127
});
149-
150-
onMounted(() => {
151-
window.addEventListener("scroll", optimiseRenderHidden);
152-
});
153-
154-
onBeforeUnmount(() => {
155-
window.removeEventListener("scroll", optimiseRenderHidden);
156-
});
157128
</script>
158129

159130
<template>

stores/events.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ import { defineStore } from "pinia";
22
import type { EventId, EventType, ServerEvent } from '~/src/shared/types';
33
import { useLockedIdsStore } from "~/stores/locked-ids";
44

5+
const MAX_EVENTS_COUNT: number = 500;
56

67
export const useEventStore = defineStore("useEventStore", {
78
state: () => ({
89
events: [] as ServerEvent<unknown>[],
910
}),
1011
actions: {
11-
initialize(events: ServerEvent<unknown>[]) {
12-
this.events = events;
12+
initialize(events: ServerEvent<unknown>[]): void {
13+
this.events = events.slice(0, MAX_EVENTS_COUNT);
1314
},
14-
addList(events: ServerEvent<unknown>[]) {
15+
addList(events: ServerEvent<unknown>[]): void {
1516
events.forEach((event) => {
16-
const isExistedEvent = this.events.some((el) => el.uuid === event.uuid);
17+
const isExistedEvent: boolean = this.events.some((el): boolean => el.uuid === event.uuid);
1718
if (!isExistedEvent) {
18-
this.events.unshift(event);
19+
this.events.unshift(event)
20+
21+
if (this.events.length > MAX_EVENTS_COUNT) {
22+
this.events.pop()
23+
}
1924
} else {
2025
this.events = this.events.map((el) => {
2126
if (el.uuid !== event.uuid) {

0 commit comments

Comments
 (0)