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:
- 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.
- 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.