Почему Merit Gem создает незаконные записи и запросы с граблями? - PullRequest
0 голосов
/ 04 января 2019

Мы установили Merit в нашем приложении Rails. Он отлично работает в среде разработчиков. Так как мы запускаем Heroku (1 января), наше приложение работает очень медленно (20 ответов на простые запросы), и мы обнаруживаем, что Merit создает много (тысячи) записей. Кроме того, когда мы обновляем правила ранга с помощью задачи rake в Heroku Scheduler (который запускается каждые 10 минут), он отправляет 10 000 запросов в секунду.

Мы попытались выяснить, в чем была проблема, и убрать нашу задачу по рейку. Теперь мы не можем обновить правила ранга и имеем полную базу данных заслуг:

Пояса: 214 045 записей

заслуга: 214 059 записей

Наше задание (выполняется каждые 10 минут с помощью Heroku Scheduler):

task cron: :environment do
  Merit::RankRules.new.check_rank_rules
end

enter image description here

См. Выдержку из журналов в конце вопроса.

Вопросы:

  • Как мы можем обновить RankRules без вызова такого количества ресурсов?

  • Как мы можем удалить все записи о заслугах «спама», но сохранить «хорошие» записи наших участников?

Большое спасибо

ЛОГИ:

2019-01-04T08:51:44.172494+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.172422 #4] DEBUG -- :   [1m[35m (0.6ms)[0m  [1m[31mROLLBACK[0m
2019-01-04T08:51:44.174077+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.173997 #4] DEBUG -- :   [1m[36mMerit::Score Load (0.7ms)[0m  [1m[34mSELECT "merit_scores".* FROM "merit_scores" WHERE "merit_scores"."sash_id" = $1[0m  [["sash_id", 197278]]
2019-01-04T08:51:44.175968+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.175906 #4] DEBUG -- :   [1m[35m (0.6ms)[0m  [1m[34mSELECT SUM("merit_score_points"."num_points") AS sum_num_points, "merit_score_points"."score_id" AS merit_score_points_score_id FROM "merit_score_points" WHERE "merit_score_points"."score_id" = $1 GROUP BY "merit_score_points"."score_id"[0m  [["score_id", 197283]]
2019-01-04T08:51:44.177333+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.177261 #4] DEBUG -- :   [1m[36mMemberRule Load (0.7ms)[0m  [1m[34mSELECT  "member_rules".* FROM "member_rules" WHERE "member_rules"."level" = $1 ORDER BY "member_rules"."id" ASC LIMIT $2[0m  [["level", 7], ["LIMIT", 1]]
2019-01-04T08:51:44.178815+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.178750 #4] DEBUG -- :   [1m[36mMember Load (0.7ms)[0m  [1m[34mSELECT  "members".* FROM "members" WHERE "members"."id" = $1 LIMIT $2[0m  [["id", 6508], ["LIMIT", 1]]
2019-01-04T08:51:44.180016+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.179955 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.181510+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.181447 #4] DEBUG -- :   [1m[36mMerit::Sash Create (0.7ms)[0m  [1m[32mINSERT INTO "sashes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"[0m  [["created_at", "2019-01-04 08:51:44.180189"], ["updated_at", "2019-01-04 08:51:44.180189"]]
2019-01-04T08:51:44.184424+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.184362 #4] DEBUG -- :   [1m[36mMerit::Score Create (0.9ms)[0m  [1m[32mINSERT INTO "merit_scores" ("sash_id") VALUES ($1) RETURNING "id"[0m  [["sash_id", 197279]]
2019-01-04T08:51:44.186445+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.186385 #4] DEBUG -- :   [1m[35m (1.5ms)[0m  [1m[35mCOMMIT[0m
2019-01-04T08:51:44.192733+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.192645 #4] DEBUG -- :   [1m[35m (2.5ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.198366+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.198296 #4] DEBUG -- :   [1m[36mMember Exists (0.9ms)[0m  [1m[34mSELECT  1 AS one FROM "members" WHERE "members"."email" = $1 AND "members"."id" != $2 LIMIT $3[0m  [["email", "guest_-spvohyxduzqeade6nup_1546579648_700@example.com"], ["id", 6508], ["LIMIT", 1]]
2019-01-04T08:51:44.199244+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.199174 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[31mROLLBACK[0m
2019-01-04T08:51:44.200789+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.200723 #4] DEBUG -- :   [1m[36mMerit::Score Load (0.7ms)[0m  [1m[34mSELECT "merit_scores".* FROM "merit_scores" WHERE "merit_scores"."sash_id" = $1[0m  [["sash_id", 197279]]
2019-01-04T08:51:44.202687+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.202628 #4] DEBUG -- :   [1m[35m (0.8ms)[0m  [1m[34mSELECT SUM("merit_score_points"."num_points") AS sum_num_points, "merit_score_points"."score_id" AS merit_score_points_score_id FROM "merit_score_points" WHERE "merit_score_points"."score_id" = $1 GROUP BY "merit_score_points"."score_id"[0m  [["score_id", 197284]]
2019-01-04T08:51:44.203901+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.203836 #4] DEBUG -- :   [1m[36mMemberRule Load (0.6ms)[0m  [1m[34mSELECT  "member_rules".* FROM "member_rules" WHERE "member_rules"."level" = $1 ORDER BY "member_rules"."id" ASC LIMIT $2[0m  [["level", 7], ["LIMIT", 1]]
2019-01-04T08:51:44.206512+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.206449 #4] DEBUG -- :   [1m[36mMember Load (1.7ms)[0m  [1m[34mSELECT  "members".* FROM "members" WHERE "members"."id" = $1 LIMIT $2[0m  [["id", 6509], ["LIMIT", 1]]
2019-01-04T08:51:44.207739+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.207681 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.209256+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.209195 #4] DEBUG -- :   [1m[36mMerit::Sash Create (0.8ms)[0m  [1m[32mINSERT INTO "sashes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"[0m  [["created_at", "2019-01-04 08:51:44.207919"], ["updated_at", "2019-01-04 08:51:44.207919"]]
2019-01-04T08:51:44.211871+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.211813 #4] DEBUG -- :   [1m[36mMerit::Score Create (0.7ms)[0m  [1m[32mINSERT INTO "merit_scores" ("sash_id") VALUES ($1) RETURNING "id"[0m  [["sash_id", 197280]]
2019-01-04T08:51:44.213538+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.213468 #4] DEBUG -- :   [1m[35m (1.4ms)[0m  [1m[35mCOMMIT[0m
2019-01-04T08:51:44.214271+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.214213 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.217872+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.217805 #4] DEBUG -- :   [1m[36mMember Exists (0.7ms)[0m  [1m[34mSELECT  1 AS one FROM "members" WHERE "members"."email" = $1 AND "members"."id" != $2 LIMIT $3[0m  [["email", "guest_dgx3f-xjkg7haph5hehl_1546579653_701@example.com"], ["id", 6509], ["LIMIT", 1]]
2019-01-04T08:51:44.218645+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.218583 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[31mROLLBACK[0m
2019-01-04T08:51:44.220025+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.219952 #4] DEBUG -- :   [1m[36mMerit::Score Load (0.7ms)[0m  [1m[34mSELECT "merit_scores".* FROM "merit_scores" WHERE "merit_scores"."sash_id" = $1[0m  [["sash_id", 197280]]
2019-01-04T08:51:44.222254+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.222167 #4] DEBUG -- :   [1m[35m (0.9ms)[0m  [1m[34mSELECT SUM("merit_score_points"."num_points") AS sum_num_points, "merit_score_points"."score_id" AS merit_score_points_score_id FROM "merit_score_points" WHERE "merit_score_points"."score_id" = $1 GROUP BY "merit_score_points"."score_id"[0m  [["score_id", 197285]]
2019-01-04T08:51:44.223549+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.223480 #4] DEBUG -- :   [1m[36mMemberRule Load (0.6ms)[0m  [1m[34mSELECT  "member_rules".* FROM "member_rules" WHERE "member_rules"."level" = $1 ORDER BY "member_rules"."id" ASC LIMIT $2[0m  [["level", 7], ["LIMIT", 1]]
2019-01-04T08:51:44.225182+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.225106 #4] DEBUG -- :   [1m[36mMember Load (0.7ms)[0m  [1m[34mSELECT  "members".* FROM "members" WHERE "members"."id" = $1 LIMIT $2[0m  [["id", 6510], ["LIMIT", 1]]
2019-01-04T08:51:44.226602+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.226533 #4] DEBUG -- :   [1m[35m (0.6ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.228011+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.227948 #4] DEBUG -- :   [1m[36mMerit::Sash Create (0.7ms)[0m  [1m[32mINSERT INTO "sashes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id"[0m  [["created_at", "2019-01-04 08:51:44.226764"], ["updated_at", "2019-01-04 08:51:44.226764"]]
2019-01-04T08:51:44.230748+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.230675 #4] DEBUG -- :   [1m[36mMerit::Score Create (0.7ms)[0m  [1m[32mINSERT INTO "merit_scores" ("sash_id") VALUES ($1) RETURNING "id"[0m  [["sash_id", 197281]]
2019-01-04T08:51:44.232442+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.232379 #4] DEBUG -- :   [1m[35m (1.2ms)[0m  [1m[35mCOMMIT[0m
2019-01-04T08:51:44.233187+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.233125 #4] DEBUG -- :   [1m[35m (0.5ms)[0m  [1m[35mBEGIN[0m
2019-01-04T08:51:44.237218+00:00 app[scheduler.7528]: D, [2019-01-04T08:51:44.237135 #4] DEBUG -- :   [1m[36mMember Exists (0.7ms)[0m  [1m[34mSELECT  1 AS one FROM "members" WHERE "members"."email" = $1 AND "members"."id" != $2 LIMIT $3[0m  [["email", "guest_2jm9cv8vhhzyc148re4d_1546579657_702@example.com"], ["id", 6510], ["LIMIT", 1]]
...