Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

User1980's avatar

Searching through a large chat room - Need advice please

Hello all,

I have a chat room project which will become very large quickly. Let's take an example of the table: id | user_id | group_id | message | read | created_at | updated_at

When a user reads a message, the read status goes from 0 to 1. Where I am not sure is on notifying the group users that some messages have not been read.

I wanted to add an index on "read", and "created_at" so I can go through all the unread messages that are older than 1 hour.

Every hour, I have a command on cron that checks all the unread messages per group and user id, then counts them and notifies each user on how many messages have been unread.

But would this makes sense to have indexes in these columns? Any tips would be appreciated please.

Thanks!

Thanks!

0 likes
0 replies

Please or to participate in this conversation.