Flow query refactor

Better flow query refactor without HSTORE

replaces https://github.com/Tahi-project/tahi/pull/717
Shouldn't there be an equivalent entry here for the new 'My Papers' flow?