rip out unnecessary references to parents_id
authorIan Beckwith <ianb@erislabs.net>
Mon, 18 Oct 2010 14:10:36 +0000 (15:10 +0100)
committerIan Beckwith <ianb@erislabs.net>
Mon, 18 Oct 2010 14:10:36 +0000 (15:10 +0100)
lib/ID3FS/Path.pm
lib/ID3FS/Path/Node.pm

index 7909a97..dcc2a85 100644 (file)
@@ -505,40 +505,10 @@ sub tags
             ") AS subselect\n" .
             "INNER JOIN files_x_tags ON subselect.files_id=files_x_tags.files_id\n" .
             "INNER JOIN tags ON files_x_tags.tags_id=tags.id\n");
-    my @allused=$self->used_tags();
-    my @used=grep { ref($_) ne "ARRAY"; } @allused;
-    my @used_with_vals=grep { ref($_) eq "ARRAY"; } @allused;
-#    print "tags(): USED: ", join(", ", @used), "\n";
-#    print "tags(): USED_WITH_VALS: ", join(", ", map { "[".$_->[0]. ", ".$_->[1]."]";} @used_with_vals), "\n";
-    my @orclauses=();
     my @andclauses=();
     my $id=$self->trailing_tag_id();
-    if($hasvals)
-    {
-#      print "HAS_VALUES\n";
-       my @values=map { "'".$_->[1]."'"; } grep { $_->[0] == $id; } @used_with_vals;
-       my $clause="(tags.parents_id='$id'";
-       if(@values)
-       {
-           $clause .= " AND tags.id NOT IN (" . join(', ', @values) . ")";
-       }
-       $clause .= ")";
-       push(@andclauses, $clause);
-    }
-    else
-    {
-#      print "HASNT VALUES\n";;
-       if(@used)
-       {
-           push(@andclauses, "(NOT (tags.parents_id='' AND tags.id IN (" . join(', ', @used) . ")))");
-       }
-       for my $pair (@used_with_vals)
-       {
-           push(@andclauses, "(NOT (tags.parents_id='" . $pair->[0] . "' AND tags.id='" . $pair->[1] . "'))");
-       }
-    }
 
-    my $parentclause= "(tags.parents_id='";
+    my $parentclause= "tags.parents_id='";
     if($hasvals)
     {
        $parentclause .= $id;
@@ -547,17 +517,19 @@ sub tags
     {
        $parentclause .= $parent;
     }
-    $parentclause .= "')";
+    $parentclause .= "'";
     push(@andclauses, $parentclause);
 
-    if(@orclauses)
+    my @used=$self->used_tags();
+    if(@used)
     {
-       push(@andclauses, '( ' . join(' OR ', @orclauses) . ' )');
+       push(@andclauses, "tags.id NOT IN (" . join(', ', @used) . ")");
     }
     if(@andclauses)
     {
        $sql .= "WHERE " . join(' AND ', @andclauses) . "\n";
     }
+
     $sql .= "GROUP BY tags.name;";
     print "SQL(TAGS): $sql\n" if($self->{verbose});
     my @tagnames=$self->{db}->cmd_firstcol($sql);
index 681a66c..dd650e4 100644 (file)
@@ -128,21 +128,11 @@ sub node_to_sql
     return $node->to_sql($hasvals, $not, @joins) if($node->type() eq "boolean");
     my $sql;
     my $cnt=scalar(@joins)+1;
-    if(defined($node->{parents_id}))
-    {
-       $sql= "(t" . scalar(@joins) . ".parents_id='$node->{parents_id}'";
-       $sql .= " AND t" . scalar(@joins) . ".id='" . $node->{id} . "'";
-    }
-    else
-    {
-       $sql= "(t" . scalar(@joins) .".parents_id=''";
-       $sql .= " AND t" . scalar(@joins) . ".id='" . $node->{id} . "'";
-    }
+    $sql .= "t" . scalar(@joins) . ".id='" . $node->{id} . "'";
     if($not && !$hasvals)
     {
        $sql .= " AND fxt" . scalar(@joins) . ".files_id IS NULL";
     }
-    $sql .= ")";
     return ($sql, ());
 }
 
@@ -156,10 +146,6 @@ sub used_tags
        push(@used, $self->right()->used_tags()) if($self->right());
        return(grep { defined; } @used);
     }
-    elsif($self->parents_id())
-    {
-       return([ $self->parents_id(), $self->id() ]);
-    }
     return $self->id();
 }