class DashboardPresenter
def initialize(member)
@member = member
end
def unread_notifications_count
@unread_notifications_count ||= Notification.where(member_id: @member.id, read_at: nil).count
end
end
Memoization is useful, but it should be scoped. Memoize within the instance/request, never globally. This is a simple way to avoid repeated expensive DB reads inside a view render.