| 1966 | | return 0 unless $type; |
| | 1966 | return undef unless $type; |
| | 1967 | my $dbh = $self->dbh; |
| | 1968 | |
| | 1969 | # Ideally we'd do this as one big query |
| | 1970 | # However, this would need a temporary table on many |
| | 1971 | # database engines, so we cheat and do it as two |
| | 1972 | my $nv_sql = |
| | 1973 | "SELECT node_id, MAX(version) ". |
| | 1974 | "FROM content ". |
| | 1975 | "WHERE moderated ". |
| | 1976 | "GROUP BY node_id "; |
| | 1977 | my $sth = $dbh->prepare( $nv_sql ); |
| | 1978 | $sth->execute(); |
| | 1979 | |
| | 1980 | my @nv_where; |
| | 1981 | while(my @results = $sth->fetchrow_array) { |
| | 1982 | my ($node_id, $version) = @results; |
| | 1983 | my $where = "(node_id=$node_id AND version=$version)"; |
| | 1984 | push @nv_where, $where; |
| | 1985 | } |
| | 1986 | |
| | 1987 | # Now the metadata bit |
| | 1988 | my $sql = |
| | 1989 | "SELECT DISTINCT metadata_value ". |
| | 1990 | "FROM metadata ". |
| | 1991 | "WHERE metadata_type = ? ". |
| | 1992 | "AND (". |
| | 1993 | join(" OR ", @nv_where). |
| | 1994 | ")"; |
| | 1995 | $sth = $dbh->prepare( $sql ); |
| | 1996 | $sth->execute($type); |
| | 1997 | |
| | 1998 | my $values = $sth->fetchall_arrayref([0]); |
| | 1999 | return ( map { $self->charset_decode( $_->[0] ) } (@$values) ); |