5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

フォロワーのTLを作る案

Posted at

書いた人(author_id)をカラムとして持つ、time_lineテーブルを使った場合、

SELECT * FROM time_line WHERE author_id IN(フォロワーID)
ORDER BY id

にようなSQLになりファイルソートが起きるし、かなり重めのSQLになってしまう。。。

レコードを作るときに、Redisに対して、

user_id array( time_line.id,・・・・)

なキャッシュを作る。
Redisのmgetコマンドで複数レコードを一気に引けるので、
1.フォロワーIDを取得
2.Redisからmgetでtime_lineのインデックスを取得
3.2をキーの降順でソートして必要な範囲を切り出す
4.

SELECT * FROM time_line WHERE id in( time_line.id,xxxx)

とするとかなりうまうまにTLを作れる気がするのでメモ

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?