Refactored get_installed_tags_with_time

- Refactored AJAX tests
- Moved `get_installed_tags_with_time` into tag model
- Refactored `get_installed_tags_with_time` and `tags_for_session`
- Awesome database optimization: 66c0a21130dc8d5ab361ec6514695c21b68668ea

See the commit messages for more detailed explanation.