Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code optimization #119

Merged
merged 3 commits into from
Apr 9, 2024
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
4 changes: 2 additions & 2 deletions src/entities/sentry/ui/sentry-exception/sentry-exception.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const exceptionFrames = computed(() => {
const frames = props.exception.stacktrace.frames || [];

if (props.maxFrames > 0) {
return frames.slice(0, props.maxFrames);
return frames.slice(0 - props.maxFrames).reverse();
}

return [...frames].reverse();
return frames.slice().reverse();
});
</script>

Expand Down
27 changes: 15 additions & 12 deletions src/shared/lib/use-api-transport/use-api-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useConnectionStore } from "~/stores/connections";
import { useEventStore } from "~/stores/events";

const CHECK_CONNECTION_INTERVAL: number = 10000

Check warning on line 7 in src/shared/lib/use-api-transport/use-api-transport.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'CHECK_CONNECTION_INTERVAL' is assigned a value but never used

Check warning on line 7 in src/shared/lib/use-api-transport/use-api-transport.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'CHECK_CONNECTION_INTERVAL' is assigned a value but never used
let isEventsEmitted: boolean = false

export const useApiTransport = () => {
Expand All @@ -24,14 +24,15 @@
} = useEventsRequests()

const getWSConnection = () => connectionStore.isConnectedWS
const checkWSConnectionFail = (onConnectionLost: () => void) => {
if (!getWSConnection()) {
onConnectionLost()
}
setTimeout(() => {
checkWSConnectionFail(onConnectionLost)
}, CHECK_CONNECTION_INTERVAL)
}
// todo: move to useCentrifuge
// const checkWSConnectionFail = (onConnectionLost: () => void) => {
// if (!getWSConnection()) {
// onConnectionLost()
// }
// setTimeout(() => {
// checkWSConnectionFail(onConnectionLost)
// }, CHECK_CONNECTION_INTERVAL)
// }

const subscribeToEvents = (): void => {
centrifuge.on('connected', () => {
Expand Down Expand Up @@ -64,10 +65,12 @@
isEventsEmitted = true
}

checkWSConnectionFail(async () => {
const events = await getAll();
eventsStore.addList(events);
})
// todo: move to useCentrifuge
// checkWSConnectionFail(async () => {
// const events = await getAll();
//
// eventsStore.addList(events);
// })

const deleteEvent = (eventId: EventId) => {
if (getWSConnection()) {
Expand Down
31 changes: 1 addition & 30 deletions src/shared/ui/preview-card/preview-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// TODO: move component out of shared/ui
import download from "downloadjs";
import { toBlob, toPng } from "html-to-image";
import debounce from "lodash.debounce";
import moment from "moment";
import { ref, computed, onMounted, onBeforeUnmount, onBeforeMount } from "vue";
import { ref, computed, onBeforeMount } from "vue";
import { REST_API_URL } from "../../lib/io";
import { useEvents } from "../../lib/use-events";
import type { NormalizedEvent } from "../../types";
Expand Down Expand Up @@ -123,37 +122,9 @@ const copyCode = () => {
}
};

const optimiseRenderHidden = debounce(() => {
if (eventRef.value) {
const eventNode = eventRef.value as HTMLElement;
const { top, height } = eventNode.getBoundingClientRect();

const extraDelta = height;
const isVisible =
top - extraDelta <= window.innerHeight &&
top + height + extraDelta * 2 >= 0;

if (!isVisible && !isOptimized.value) {
isOptimized.value = true;
eventNode.style.height = `${eventNode.clientHeight}px`;
} else if (isVisible && isOptimized.value) {
isOptimized.value = false;
eventNode.style.height = "auto";
}
}
}, 30);

onBeforeMount(() => {
isLocked.value = lockedIds.items.value.includes(props.event.id);
});

onMounted(() => {
window.addEventListener("scroll", optimiseRenderHidden);
});

onBeforeUnmount(() => {
window.removeEventListener("scroll", optimiseRenderHidden);
});
</script>

<template>
Expand Down
15 changes: 10 additions & 5 deletions stores/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ import { defineStore } from "pinia";
import type { EventId, EventType, ServerEvent } from '~/src/shared/types';
import { useLockedIdsStore } from "~/stores/locked-ids";

const MAX_EVENTS_COUNT: number = 500;

export const useEventStore = defineStore("useEventStore", {
state: () => ({
events: [] as ServerEvent<unknown>[],
}),
actions: {
initialize(events: ServerEvent<unknown>[]) {
this.events = events;
initialize(events: ServerEvent<unknown>[]): void {
this.events = events.slice(0, MAX_EVENTS_COUNT);
},
addList(events: ServerEvent<unknown>[]) {
addList(events: ServerEvent<unknown>[]): void {
events.forEach((event) => {
const isExistedEvent = this.events.some((el) => el.uuid === event.uuid);
const isExistedEvent: boolean = this.events.some((el): boolean => el.uuid === event.uuid);
if (!isExistedEvent) {
this.events.unshift(event);
this.events.unshift(event)

if (this.events.length > MAX_EVENTS_COUNT) {
this.events.pop()
}
} else {
this.events = this.events.map((el) => {
if (el.uuid !== event.uuid) {
Expand Down
Loading