Some fixes
Fix inconsitent 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.