Skip to content

Commit

Permalink
Item10331: implement a trivial version of OP_ref - it will kill the m…
Browse files Browse the repository at this point in the history
…ongodb query if there is even one topic for which the array element does not exist

git-svn-id: http://svn.foswiki.org/trunk@10973 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Mar 8, 2011
1 parent 152ed9f commit eab3650
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/lib/Foswiki/Meta.pm
Expand Up @@ -1203,6 +1203,8 @@ sub get {
my $data = $this->{$type};
if ($data) {
if ( defined $name ) {
#this code presumes the _indices are there (Sven would like it to re-create when needed..)
ASSERT(defined($this->{_indices})) if DEBUG;
my $indices = $this->{_indices}->{$type};
return undef unless defined $indices;
return undef unless defined $indices->{$name};
Expand Down
8 changes: 6 additions & 2 deletions core/lib/Foswiki/Query/Node.pm
Expand Up @@ -158,20 +158,24 @@ sub evaluate {
if ( $this->{op} == Foswiki::Infix::Node::NAME
&& defined $domain{data} )
{

print STDERR '.' if MONITOR_EVAL;
if (lc($this->{params}[0]) eq 'now') {
$result = time();
} elsif (lc($this->{params}[0]) eq 'undefined') {
$result = undef;
} else {
# a name; look it up in $domain{data}
eval "require $Foswiki::cfg{Store}{QueryAlgorithm}";
die $@ if $@;
if ($@) {
print STDERR ' BOOM ' if MONITOR_EVAL;
die $@ ;
}
$result = $Foswiki::cfg{Store}{QueryAlgorithm}->getField(
$this, $domain{data}, $this->{params}[0] );
}
}
else {
print STDERR ',' if MONITOR_EVAL;
$result = $this->{params}[0];
}
}
Expand Down
24 changes: 22 additions & 2 deletions core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm
@@ -1,6 +1,8 @@
# See bottom of file for license and copyright information
package Foswiki::Store::Interfaces::QueryAlgorithm;

use constant MONITOR => 0;

=begin TML
---+ package Foswiki::Store::Interfaces::QueryAlgorithm
Expand Down Expand Up @@ -84,7 +86,7 @@ sub getField {
}
}
elsif ( $realField eq 'versions' ) {

print STDERR "----- getField(versions)\n" if MONITOR;
# Disallow reloading versions for an object loaded here
# SMELL: violates Foswiki::Meta encapsulation
return [] if $data->{_loadedByQueryAlgorithm};
Expand All @@ -102,24 +104,29 @@ sub getField {
return \@revs;
}
elsif ( $realField eq 'name' ) {
print STDERR "----- getField(name)\n" if MONITOR;

# Special accessor to compensate for lack of a topic
# name anywhere in the saved fields of meta
return $data->topic();
}
elsif ( $realField eq 'text' ) {
print STDERR "----- getField(text)\n" if MONITOR;

# Special accessor to compensate for lack of the topic text
# name anywhere in the saved fields of meta
return $data->text();
}
elsif ( $realField eq 'web' ) {
print STDERR "----- getField(web)\n" if MONITOR;

# Special accessor to compensate for lack of a web
# name anywhere in the saved fields of meta
return $data->web();
}
elsif ( $realField eq ':topic_meta:' ) {
print STDERR "----- getField(:topic_meta:)\n" if MONITOR;

#TODO: Sven expects this to be replaced with a fast call to verions[0] - atm, thats needlessly slow
# return the meta obj itself
#actually should do this the way the versions feature is supposed to return a particular one..
Expand All @@ -131,6 +138,7 @@ sub getField {
# the form name
my $form = $data->get('FORM');
if ( $form && $field eq $form->{name} ) {
print STDERR "----- getField(FORM: $field)\n" if MONITOR;

# SHORTCUT;it's the form name, so give me the fields
# as if the 'field' keyword had been used.
Expand All @@ -140,6 +148,12 @@ sub getField {
return \@e;
}
else {
if (MONITOR) {
print STDERR "----- getField(FIELD value $field)\n" if MONITOR;
use Data::Dumper;
print STDERR Dumper($data)."\n";

}

# SHORTCUT; not a predefined name; assume it's a field
# 'name' instead.
Expand All @@ -160,6 +174,7 @@ sub getField {
# 1. An integer, which is an implicit index='x' query
# 2. A name, which is an implicit name='x' query
if ( $field =~ /^\d+$/ ) {
print STDERR "----- getField(index $field)\n" if MONITOR;

# Integer index
$result = $data->[$field];
Expand Down Expand Up @@ -197,12 +212,15 @@ sub getField {
}
}
elsif ( ref($data) eq 'HASH' ) {
print STDERR "----- getField(HASH ".$node->{params}[0].")\n" if MONITOR;

# A hash object may be returned when a sub-object of a Foswiki::Meta
# object has been matched.
$result = $data->{ $node->{params}[0] };
}
else {
print STDERR "----- getField(value ".$node->{params}[0].")\n" if MONITOR;

$result = $node->{params}[0];
}
return $result;
Expand All @@ -228,7 +246,9 @@ sub getRefTopic {

# Get a referenced topic
my ( $this, $relativeTo, $w, $t, $rev ) = @_;
return Foswiki::Meta->load( $relativeTo->session, $w, $t, $rev );
my $meta = Foswiki::Meta->load( $relativeTo->session, $w, $t, $rev );
print STDERR "----- getRefTopic($w, $t) -> ".($meta->getLoadedRev())."\n" if MONITOR;
return $meta;
}

1;
Expand Down

0 comments on commit eab3650

Please sign in to comment.