Fix duplicate IDs in queries for comments/downtimes.

Fixes #5283
ScriptVariableRegistry::GetInstance should not be defined inline.

Fixes #5284