Backports of ad6874821711208d0e420ee2168862b59cf16cef, 98d01e01e0064fa62e1cda75363805c50398220d, d388d7ad9e5660973cddd81e09cc52ec4e8e2595, b2f6b7759e6345b1a81f9e9b1b3b6fedfefd84ce from master.
Backport dd962958f73efb95216044f93de9aea3aace01e8 from master.
LP: #1507712 - cli: maas logout causes KeyError for other profiles
There is a race where when profiles are being deleted, if this happens
between the __iter__ and __getitem__ (of a different invocation of the
cli) which are two different SQL queries, there is an inconsistent view.
So instead use a cache with a consistent view of the data. This
guarantees correct -- if stale behavior in the cli.
Note that this is acceptable because when running two commands at the
same time ordering is unknown and the cache only lives for the lifetime
of a single command.
Backport 0a9d968925552226479a80333240943f3cb504af from master.
LP: #1715634 - Prefetch all node data in the tags API so SQL queries are consistent.
With the nodes, machines, devices, rack_controllers, and region_controllers on the tags endpoint returning the correct objects Piston will convert them into the correct result object which results in large number of queries per node. This prefetches all the required data making the number of queries consistent.