# Performance optimisation tips

**URL:** <https://meta.discourse.org/t/performance-optimisation-tips/226812>\
**Category:** Self-hosting\
**Created:** [May 11, 2022, 10:19pm UTC](https://meta.discourse.org/t/performance-optimisation-tips/226812 "2022-05-11T22:19:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Dmitry\_Krasnoperov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dmitry_krasnoperov/32/65079_2.png) [@Dmitry\_Krasnoperov](https://meta.discourse.org/u/Dmitry_Krasnoperov)\
**Post date:** [June 15, 2022, 12:39pm UTC](https://meta.discourse.org/t/performance-optimisation-tips/226812/4 "2022-06-15T12:39:46Z")

</div>

So I moved my server to another more powerfull hosting via clean install and restore from backup. Yep, it much faster now! But there is some bottleneck in Like function. It takes 23 second to create Like.

 ![Снимок экрана 2022-06-15 в 15.28.22](https://global.discourse-cdn.com/meta/original/4X/d/4/f/d4f6e50b3b82eaac61e1cf3918296cb1ff235fde.png)

Executing action: create  
T+229.3 ms  
Reader  
**23169.7 ms**

```plaintext
app/models/topic_user.rb:463:in `update_post_action_cache'
app/models/post_action.rb:232:in `update_counters'
lib/post_action_creator.rb:268:in `create_post_action'
lib/post_action_creator.rb:112:in `perform'
app/controllers/post_actions_controller.rb:22:in `create'
app/controllers/application_controller.rb:415:in `block in with_resolved_locale'
app/controllers/application_controller.rb:415:in `with_resolved_locale'
lib/middleware/omniauth_bypass_middleware.rb:71:in `call'
lib/content_security_policy/middleware.rb:12:in `call'
lib/middleware/anonymous_cache.rb:368:in `call'
config/initializers/100-quiet_logger.rb:23:in `call'
config/initializers/100-silence_logger.rb:31:in `call'
lib/middleware/enforce_hostname.rb:23:in `call'
lib/middleware/request_tracker.rb:202:in `call'
UPDATE topic_users tu
SET liked = x.state
FROM (
  SELECT CASE WHEN EXISTS (
    SELECT 1
    FROM post_actions pa
    JOIN posts p on p.id = pa.post_id
    JOIN topics t ON t.id = p.topic_id
    WHERE pa.deleted_at IS NULL AND
          p.deleted_at IS NULL AND
          t.deleted_at IS NULL AND
          pa.post_action_type_id = 2 AND
          tu2.topic_id = t.id AND
          tu2.user_id = pa.user_id
    LIMIT 1
  ) THEN true ELSE false END state, tu2.topic_id, tu2.user_id
  FROM topic_users tu2
  WHERE (tu2.user_id IN (1)) AND (tu2.topic_id IN (127680))
) x
WHERE x.topic_id = tu.topic_id AND x.user_id = tu.user_id AND x.state != tu.liked
;

```

I need to more time to settle DB and re-indexing or there is a problem?

---

_[View the full topic](https://meta.discourse.org/t/performance-optimisation-tips/226812)._
