Skip to content

Comments

feat: Realtime Increment View Count Without Refreshing Pages#10760

Merged
mergify[bot] merged 3 commits intomasterfrom
feat/175879-realtime-increment-view-count
Feb 4, 2026
Merged

feat: Realtime Increment View Count Without Refreshing Pages#10760
mergify[bot] merged 3 commits intomasterfrom
feat/175879-realtime-increment-view-count

Conversation

@ryotaro-nagahara
Copy link

@ryotaro-nagahara ryotaro-nagahara commented Jan 30, 2026

Task

https://redmine.weseek.co.jp/issues/178067

変更点

サーバーサイド: EventEmitter → Socket io の橋渡し

  • websocket.ts : PageSeenUsersUpdated イベント名定数を追加
  • s2c-message.ts : S2cMessagePageSeenUsersUpdated クラスを追加(pageId, seenUserIds, seenUsersCount を送信)
  • sync-page-status.ts : addSeenUsers リスナーを追加し、既存の create/update/delete と同じパターンでpage:seenUsersUpdated を同一ページの room に送信

クライアントサイド: Socket io 受信 → UI更新

  • page-seen-users-updated.ts(新規ファイル) : Socket io イベントを受信し、SWRキャッシュの sumOfSeenUsers と seenUserIds を直接更新するフック
  • EditablePageEffects.tsx : 上記フックを登録

socketIoService
.getDefaultSocket()
.in(getRoomNameWithId(RoomPrefix.PAGE, page._id))
.emit('page:seenUsersUpdated', { s2cMessagePageSeenUsersUpdated });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/src/interfaces/websocket.ts に追加した PageSeenUsersUpdated を使うようにしましょう

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下のように修正いたしました。

  • S2cMessagePageSeenUsersUpdated クラスを削除し、Socket.IO メッセージを { pageId } のみに簡素化
  • 既存の SyncPageStatusService のリスナー構造はそのまま活用

this.pageId = serializedPage._id;
this.seenUserIds = serializedPage.seenUsers
.slice(0, 15)
.map((id: any) => (typeof id === 'string' ? id : id.toString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts の恩恵がなくなるので any はなるべく使わないようにしてください

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらのFB通り、クライアント側の既存データを書き換えをやめたので、クラスS2cMessagePageSeenUsersUpdated自体を削除しました

Comment on lines 28 to 36
(currentData) => {
if (currentData == null) return currentData;
return {
...currentData,
seenUserIds: s2cMessagePageSeenUsersUpdated.seenUserIds,
sumOfSeenUsers: s2cMessagePageSeenUsersUpdated.seenUsersCount,
};
},
{ revalidate: false },
Copy link
Member

@miya miya Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • これって mutatePageInfo をただ呼ぶだけじゃだめかな?
  • socket.io を通じて受け取ったデータでクライアント側の既存データを書き換えると実装が複雑になるので、単純に page:seenUsersUpdated イベントが発火したらサーバーからデータを再 fetch するみたいな感じの方がシンプルだと思う
  • ↑ を採用する場合はサーバー側は pageId だけを送るだけで良いので S2cMessagePageSeenUsersUpdated は不要 (冗長) だと思う

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FBいただいた内容の通り、以下のように修正しました。

  • seenUserIds, sumOfSeenUsersを廃止し、
  • mutatePageInfo() を引数なしで呼び、既存の /page/info APIから再fetchする方式に変更

@ryotaro-nagahara ryotaro-nagahara requested a review from miya February 2, 2026 06:39
socketIoService
.getDefaultSocket()
.in(getRoomNameWithId(RoomPrefix.PAGE, page._id))
.emit('page:seenUsersUpdated', { pageId });
Copy link
Member

@miya miya Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

page:seenUsersUpdated がハードコードのままになっているので SocketEventName.PageSeenUsersUpdated を使うように修正してください

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正いたしました。

@yuki-takei
Copy link
Contributor

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Feb 4, 2026

queue

✅ The pull request has been merged automatically

Details

The pull request has been merged automatically at 89538c8

@mergify
Copy link
Contributor

mergify bot commented Feb 4, 2026

Merge Queue Status

✅ The pull request has been merged at 4435928

This pull request spent 13 minutes 4 seconds in the queue, including 12 minutes 40 seconds running CI.
The checks were run on draft #10766.

Required conditions to merge
  • -check-failure ~= ci-app-
  • -check-failure ~= ci-slackbot-
  • -check-failure ~= test-prod-node20 /
  • check-success = test-prod-node20 / build-prod
  • check-success ~= ci-app-launch-dev
  • check-success ~= ci-app-lint
  • check-success ~= ci-app-test
  • check-success ~= test-prod-node20 / launch-prod
  • check-success ~= test-prod-node20 / run-playwright

@mergify mergify bot added the queued label Feb 4, 2026
mergify bot added a commit that referenced this pull request Feb 4, 2026
mergify bot added a commit that referenced this pull request Feb 4, 2026
mergify bot added a commit that referenced this pull request Feb 4, 2026
@mergify mergify bot merged commit 89538c8 into master Feb 4, 2026
30 of 32 checks passed
@mergify mergify bot deleted the feat/175879-realtime-increment-view-count branch February 4, 2026 09:55
@mergify mergify bot removed the queued label Feb 4, 2026
@github-actions github-actions bot mentioned this pull request Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants