Fix inconsistent idQueue and ids in saved queries

- Some dashboard can be saved using non-compact ids array for queries,
- PR ensures that nextId() returns a valid identifier:
  - either one from the queue that is not used in the ids array
  - or one that is not used in the array
  - of the usual ids.length when ids is compact and idQueue is empty.

also fix _q helper with a method. Debugging show that there the variable was not always up to date re the idQueue