Skip to content

Commit 47ddfae

Browse files
committed
Code optimization
1. Use max events instead of preview card optimization 2. Fix slising max frames for Sentry exception 3. Disable WS connection check
1 parent 6c71c24 commit 47ddfae

File tree

4 files changed

+28
-50
lines changed

4 files changed

+28
-50
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.reverse().slice(0, props.maxFrames);
19+
return frames.slice(0 - props.maxFrames).reverse();
2020
}
2121
22-
return frames;
22+
return frames.slice().reverse();
2323
});
2424
</script>
2525

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ export const useApiTransport = () => {
2222
} = useEventsRequests()
2323

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

3435
const subscribeToEvents = (): void => {
3536
centrifuge.on('connected', () => {
@@ -62,11 +63,12 @@ export const useApiTransport = () => {
6263
isEventsEmitted = true
6364
}
6465

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

7173
const deleteEvent = (eventId: EventId) => {
7274
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)