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

성능 개선을 위해 퍼포먼스 모니터링 API 추가 #140

Merged
merged 3 commits into from
Jan 27, 2025
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
2 changes: 2 additions & 0 deletions src/components/pages/board/PostCardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePosts } from '@/hooks/usePosts';
import { useInView } from 'react-intersection-observer';
import PostCardSkeleton from '@/components/ui/PostCardSkeleton';
import { useScrollRestoration } from '@/hooks/useScrollRestoration';
import { usePerformanceMonitoring } from '@/hooks/usePerformanceMonitoring';
interface PostCardListProps {
boardId: string;
onPostClick: (postId: string) => void;
Expand All @@ -14,6 +15,7 @@ interface PostCardListProps {
const PostCardList: React.FC<PostCardListProps> = ({ boardId, onPostClick, selectedAuthorId }) => {
const [inViewRef, inView] = useInView();
const [limitCount] = useState(7);
usePerformanceMonitoring('PostCardList')

const {
data: postPages,
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/notification/NotificationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { useInView } from 'react-intersection-observer';
import { Loader2 } from 'lucide-react';
import { useNotifications } from '@/hooks/useNotifications';
import { Skeleton } from '@/components/ui/skeleton';
import { usePerformanceMonitoring } from '@/hooks/usePerformanceMonitoring';
const NotificationsPage: React.FC = () => {
usePerformanceMonitoring('NotificationsPage');
const { currentUser } = useAuth();
const [inViewRef, inView] = useInView();
const [limitCount] = useState(10);
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/stats/StatsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { UserStatsCard } from "./UserStatsCard"
import { useWritingStats } from "@/hooks/useWritingStats"
import StatsHeader from "./StatsHeader"
import { StatsNoticeBanner } from "./StatsNoticeBanner"
import { usePerformanceMonitoring } from "@/hooks/usePerformanceMonitoring"

export default function StatsPage() {
usePerformanceMonitoring('StatsPage');
const { writingStats, isLoading, error } = useWritingStats()

if (isLoading) {
Expand Down
4 changes: 3 additions & 1 deletion src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UserCredential,
} from 'firebase/auth';
import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore';
import { getPerformance } from "firebase/performance";
import { getStorage } from 'firebase/storage';
import { getFunctions, connectFunctionsEmulator } from 'firebase/functions';

Expand All @@ -30,6 +31,7 @@ const storage = getStorage(app);
const functions = getFunctions(app);
// Google Auth Provider
const provider = new GoogleAuthProvider();
const performance = getPerformance(app);

// Auth functions
const signInWithGoogle = async (): Promise<UserCredential> => {
Expand Down Expand Up @@ -59,4 +61,4 @@ if (process.env.NODE_ENV === 'development') {
}


export { auth, firestore, signInWithGoogle, signOutUser, storage, app };
export { auth, firestore, signInWithGoogle, signOutUser, storage, app, performance };
16 changes: 16 additions & 0 deletions src/hooks/usePerformanceMonitoring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useEffect } from 'react';
import { trace } from 'firebase/performance';
import { performance } from '@/firebase';

export function usePerformanceMonitoring(pageName: string) {
useEffect(() => {
if (!performance) return;

const pageLoadTrace = trace(performance, `${pageName}_page_load`);
pageLoadTrace.start();

return () => {
pageLoadTrace.stop();
};
}, [pageName]);
}
Loading