Fixing generation slowness when having rules with databases dependencies

Reducing gerenation time from `5 min` to `0.7 sec`