Backport fix to optimize code for polls to avoid run queries in loop
Merge pull request #1993 from xillibit/k30_bugs12

Backport fix to optimize code for polls to avoid run queries in loop