Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spam checking in rails

I am using rakismet to check for spam in comments.

Right now, I do it in a before_create callback and I am wondering in a production site, if this is the most efficient way of doing it or should this be done by a background job.

Can you share your experience in terms of how much delay does this add to the responsiveness of your production apps?

like image 842
badnaam Avatar asked Nov 15 '22 07:11

badnaam


1 Answers

I have not used rakisment, but doing any pre-processing on an action will slow it down, and in the situation of your spam filter, it will slow down more and more as more spam indicators are included in the rakismet dictionary.

I would recommend a two step process:

  1. In the before_create, do a minimal spam check to catch very obvious ones. You can search for words ("viagra", "cialis", "debt", etc), as well as check that the submitter isn't submitting many comments very fast. This will be fairly quick, and not slow your app down too much.
  2. In a Delayed Job (One of the more well known background processing libraries for Ruby), run your rakismet checks. These can delete/flag the comments after the fact.

This solution limits blatant spam immediately, and will eventually leverage the capabilities of rakismet to clean up the comments entirely, without causing too much strain or slow down to the system.

One benefit of this approach is that it is extremely easy to scale your Delayed Job processes, but just starting more workers on the same (or different) server(s). This means that your main app won't crawl, as the heavy lifting has been offloaded to multiple instances of the worker process.

like image 74
Mike Trpcic Avatar answered Nov 24 '22 00:11

Mike Trpcic