chiark / gitweb /
Better answers for arch queries
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 22 Aug 2009 13:01:05 +0000 (14:01 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 22 Aug 2009 13:01:05 +0000 (14:01 +0100)
yarrg/web/routetrade

index ad82657..9a7b036 100644 (file)
@@ -12,7 +12,7 @@ my $sd_condition= sub {
        my ($bs, $ix) = @_;
        my $islandid= $islandids[$ix];
        if (defined $islandid) {
-               return "${bs}_islands.islandid = $islandid";
+               return "${bs}.islandid = $islandid";
        } else {
                push @query_params, $archipelagoes[$ix];
                return "${bs}_islands.archipelago = ?";
@@ -23,7 +23,14 @@ foreach my $src_i (0..$#islandids) {
        my $src_cond= $sd_condition->('sell',$src_i);
        my @dst_conds;
        foreach my $dst_i ($src_i..$#islandids) {
-               push @dst_conds, $sd_condition->('buy',$dst_i);
+               my $dst_cond= $sd_condition->('buy',$dst_i);
+               if ($dst_i==$src_i and !defined $islandids[$src_i]) {
+                       # we always want arbitrage, but mentioning an arch
+                       # once shouldn't produce intra-arch trades
+                       $dst_cond=
+                               "($dst_cond AND sell.islandid = buy.islandid)";
+               }
+               push @dst_conds, $dst_cond;
        }
        push @flow_conds, "$src_cond AND (
                        ".join("