<oils_persist:source_definition><![CDATA[
SELECT
ahr.*,
- COALESCE(acplo.position, 999) AS
+ COALESCE(acplo.position, acpl_ordered.fallback_position) AS
copy_location_order_position,
CASE WHEN au.alias IS NOT NULL THEN
au.alias
JOIN asset.call_number_prefix acnp ON (acn.prefix = acnp.id)
JOIN asset.call_number_suffix acns ON (acn.suffix = acns.id)
JOIN actor.usr au ON (au.id = ahr.usr)
+ JOIN (
+ SELECT *, (ROW_NUMBER() OVER (ORDER BY name) + 1000000) AS fallback_position
+ FROM asset.copy_location
+ ) acpl_ordered ON (acpl_ordered.id = acp.location)
LEFT JOIN actor.usr_standing_penalty ausp
ON (ahr.usr = ausp.usr AND (ausp.stop_date IS NULL OR ausp.stop_date > NOW()))
LEFT JOIN config.standing_penalty csp
use OpenILS::Utils::CStoreEditor q/:funcs/;
use OpenSRF::Utils::JSON;
+use Data::Dumper;
+
+$Data::Dumper::Indent = 0;
+
sub _fm_link_from_class {
my ($class, $field) = @_;
join => {}
};
+ # Here's a hash where we'll keep track of whether we've already provided
+ # a join to cover a given hash. It seems that without this we build
+ # redundant joins.
+ my $join_coverage = {};
+
foreach my $k (keys %$map) {
my $column = $map->{$k} =
_flattened_search_normalize_map_column($map->{$k});
# For filter or sort columns, we'll need joining.
if ($column->{filter} or $column->{sort}) {
- my ($clause, $last_join_alias) =
- _flattened_search_single_join_clause($k,$hint,$column->{path});
+ my @path = @{ $column->{path} };
+ pop @path; # discard last part (field)
+ my $joinkey = join(",", @path);
+
+ my ($clause, $last_join_alias);
+
+ # Skip joins that are already covered. We shouldn't need more than
+ # one join for the same path
+ if ($join_coverage->{$joinkey}) {
+ ($clause, $last_join_alias) = @{ $join_coverage->{$joinkey} };
+ } else {
+ ($clause, $last_join_alias) =
+ _flattened_search_single_join_clause(
+ $k, $hint, $column->{path}
+ );
+ $join_coverage->{$joinkey} = [$clause, $last_join_alias];
+ }
$map->{$k}{last_join_alias} = $last_join_alias;
_flattened_search_merge_join_clause($jffolo->{join}, $clause);
if ($map->{$key}) {
my $class = $map->{$key}{last_join_alias} || $core_hint;
+
push @{ $jffolo->{order_by} }, {
class => $class,
field => $map->{$key}{path}[-1],
if (not ref $fmobj) {
throw OpenSRF::EX::ERROR(
- "process_result() was passed an inappropriate second argument"
+ "process_result() was passed an inappropriate second argument ($fmobj)"
);
}