Skip to content

Commit 5319e50

Browse files
committed
chore: 네트워크 성능 모니터링 코드 추가
1 parent 7ebdfe8 commit 5319e50

File tree

4 files changed

+189
-77
lines changed

4 files changed

+189
-77
lines changed

@noctaCrdt/Interfaces.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,34 @@ export interface DeleteOperation {
7777
clock: number;
7878
}
7979

80-
export interface RemotePageCreateOperation {
80+
export interface RemotePageCreateOperation extends BaseOperation {
8181
type: "pageCreate";
8282
clientId: number;
8383
workspaceId: string;
8484
page?: Page;
8585
}
8686

87-
export interface RemotePageDeleteOperation {
87+
export interface RemotePageDeleteOperation extends BaseOperation {
8888
type: "pageDelete";
8989
clientId: number;
9090
workspaceId: string;
9191
pageTitle: string;
9292
pageId: string;
9393
}
9494

95-
export interface RemoteBlockUpdateOperation {
95+
export interface RemoteBlockUpdateOperation extends BaseOperation {
9696
type: "blockUpdate";
9797
node: Block;
9898
pageId: string;
9999
}
100100

101-
export interface RemoteBlockInsertOperation {
101+
export interface RemoteBlockInsertOperation extends BaseOperation {
102102
type: "blockInsert";
103103
node: Block;
104104
pageId: string;
105105
}
106106

107-
export interface RemoteCharInsertOperation {
107+
export interface RemoteCharInsertOperation extends BaseOperation {
108108
type: "charInsert";
109109
node: Char;
110110
blockId: BlockId;
@@ -114,36 +114,36 @@ export interface RemoteCharInsertOperation {
114114
backgroundColor?: BackgroundColorType;
115115
}
116116

117-
export interface RemoteBlockDeleteOperation {
117+
export interface RemoteBlockDeleteOperation extends BaseOperation {
118118
type: "blockDelete";
119119
targetId: BlockId;
120120
clock: number;
121121
pageId: string;
122122
}
123123

124-
export interface RemoteBlockCheckboxOperation {
124+
export interface RemoteBlockCheckboxOperation extends BaseOperation {
125125
type: "blockCheckbox";
126126
blockId: BlockId;
127127
isChecked: boolean;
128128
pageId: string;
129129
}
130130

131-
export interface RemoteCharDeleteOperation {
131+
export interface RemoteCharDeleteOperation extends BaseOperation {
132132
type: "charDelete";
133133
targetId: CharId;
134134
clock: number;
135135
blockId?: BlockId;
136136
pageId: string;
137137
}
138138

139-
export interface RemoteCharUpdateOperation {
139+
export interface RemoteCharUpdateOperation extends BaseOperation {
140140
type: "charUpdate";
141141
node: Char;
142142
blockId: BlockId;
143143
pageId: string;
144144
}
145145

146-
export interface CursorPosition {
146+
export interface CursorPosition extends BaseOperation {
147147
type: "cursor";
148148
clientId: number;
149149
position: number;
@@ -183,7 +183,7 @@ export interface ReorderNodesProps {
183183
afterId: BlockId | null;
184184
}
185185

186-
export interface RemotePageUpdateOperation {
186+
export interface RemotePageUpdateOperation extends BaseOperation {
187187
type: "pageUpdate";
188188
workspaceId: string;
189189
pageId: string;
@@ -197,7 +197,7 @@ export interface WorkSpaceSerializedProps {
197197
pageList: Page[];
198198
authUser: Map<string, string>;
199199
}
200-
export interface RemoteBlockReorderOperation {
200+
export interface RemoteBlockReorderOperation extends BaseOperation {
201201
type: "blockReorder";
202202
targetId: BlockId;
203203
beforeId: BlockId | null;
@@ -213,3 +213,27 @@ export interface WorkspaceListItem {
213213
memberCount: number;
214214
activeUsers: number;
215215
}
216+
217+
// 서버 처리 시간과 수신 시간을 포함하는 기본 인터페이스
218+
interface BaseOperation {
219+
serverProcessingTime?: number;
220+
serverReceiveTime?: number;
221+
}
222+
223+
export interface BatchOperationData extends BaseOperation {
224+
batch: Operation[];
225+
}
226+
227+
// Operation 유니온 타입 업데이트
228+
export type Operation =
229+
| RemoteBlockInsertOperation
230+
| RemoteBlockDeleteOperation
231+
| RemoteBlockUpdateOperation
232+
| RemoteBlockReorderOperation
233+
| RemoteCharInsertOperation
234+
| RemoteCharDeleteOperation
235+
| RemoteCharUpdateOperation
236+
| RemotePageCreateOperation
237+
| RemotePageDeleteOperation
238+
| RemotePageUpdateOperation
239+
| RemoteBlockCheckboxOperation;

client/src/features/editor/Editor.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ export const Editor = ({ onTitleChange, pageId, pageTitle, serializedEditorData
338338
handleRemoteCursor,
339339
]);
340340

341+
useEffect(() => {
342+
const statsInterval = setInterval(() => {
343+
useSocketStore.getState().logNetworkStats();
344+
}, 10000); // 10초마다 통계 출력
345+
346+
return () => clearInterval(statsInterval);
347+
}, []);
348+
341349
// 로딩 상태 체크
342350
if (!editorCRDT || !editorState) {
343351
return <div>Loading editor data...</div>;

0 commit comments

Comments
 (0)