Tests should be done for TSDB class.

Why the outer `if` clause? This is not a performance sensitive area and if `trees_id` is empty won't the `for` block be skipped anyway