Junior — Senior
Increasing the request speed in a social network
livecode
Task condition
Suggest options for speeding up query performance without changing the business logic of the social platform, where the page load time increases with the number of likes on a post.
The system has models for data storage:
class Post(Base):
id: Mapped[int]
name: Mapped[str]
class Like(Base):
id: Mapped[int]
user_id: Mapped[int]
The current query, which retrieves a post along with the number of likes, uses a subquery:
select *, (select count(*) from like where like.post_id = post.id) as like_count
from post
where post.id = :id
Describe what techniques (indexing, query structure modification, caching, etc.) can be applied to reduce execution time while maintaining the application's previous behavior.