Ignore:
Timestamp:
2013-05-07T19:32:42+12:00 (11 years ago)
Author:
ak19
Message:

Now the existing user comments to be displayed are all retrieved in one go using the new get_metadata_array subroutine in metadataaction.pm via the new gsajaxapi method getMetadataArray which take a JSON string and return one. This loads user comments much faster, and doesn't get that much slower if the number of comments stored in the index database gets larger. 2 bugfixes to metadataaction.pm's recently added get_metadata_array subroutine: if no metapos supplied it defaults to 0 like the other get_meta functions instead of defaulting to the keyword 'all'. The fieldnames in the JSON string returned also needed to be inside double quotes in order to be successfully parsed back into a JSON object on the Javascript side. Replaced the old loadUserComments() javascript function in style.dm, which now calls the new gsajaxapi.getMetadataArray() post method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r27312 r27313  
    270270
    271271# takes a JSON string and returns a JSON string
     272# resulting string is of the form:
     273# [{"docid":"HASHc5bce2d6d3e5b04e470ec9","metatable":[{"metaname":"username","metavals":[{"metapos":"0","metavalue":"me"},{"metapos":"1","metavalue":"admin"}]},{"metaname":"usertimestamp","metavals":[{"metapos":"0","metavalue":"1367900586888"},{"metapos":"1","metavalue":"1367900616574"}]},{"metaname":"usercomment","metavals":[{"metapos":"0","metavalue":"Hi"},{"metapos":"1","metavalue":"Hello"}]}]}]
    272274sub _get_index_metadata_array
    273275{
     
    304306        $json_result_str .= ",";
    305307    }
    306     $json_result_str = $json_result_str . "{docid:\"" . $docid . "\""; 
     308    $json_result_str = $json_result_str . "{\"docid\":\"" . $docid . "\""; 
    307309
    308310    my $metatable = $doc_array_rec->{'metatable'}; # a subarray, or need to generate an error saying JSON structure is wrong
    309     $json_result_str = $json_result_str . ",metatable:[";
     311    $json_result_str = $json_result_str . ",\"metatable\":[";
    310312
    311313    my $first_rec = 1;
     
    318320       
    319321        my $metaname  = $metatable_rec->{'metaname'};
    320         $json_result_str .= "{metaname:\"$metaname\",metavals:[";
     322        $json_result_str .= "{\"metaname\":\"$metaname\",\"metavals\":[";
    321323
    322324        my $metapos   = $metatable_rec->{'metapos'}; # 0... 1|all|undefined
    323325        if(!defined $metapos) {
    324         $metapos = "all";
     326        $metapos = 0;
    325327        }
    326328
     
    344346
    345347        $metavalue = $doc_rec->{$metaname}->[$metapos];     
    346         $json_result_str .= "{metapos:\"$metapos\",metavalue:\"$metavalue\"}";
     348        $json_result_str .= "{\"metapos\":\"$metapos\",\"metavalue\":\"$metavalue\"}";
    347349
    348350        } else {
     
    358360            }
    359361       
    360             $json_result_str .= "{metapos:\"$metapos\",metavalue:\"$metavalue\"}";
     362            $json_result_str .= "{\"metapos\":\"$metapos\",\"metavalue\":\"$metavalue\"}";
    361363
    362364            $metapos++;
Note: See TracChangeset for help on using the changeset viewer.