Skip to content

Commit

Permalink
Issue #9 - cache the mapping of APIs to post IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Feb 19, 2016
1 parent 04b52fb commit 99d62d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
6 changes: 3 additions & 3 deletions classes/class-oiksc-link-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/


/**
* Cached mapping of API names to post IDs
*/
class oiksc_link_map {


Expand Down Expand Up @@ -59,9 +62,6 @@ function get_permalink( $post_id=null ) {
}
return( $this->post_ids[ $post_id ] );
}




}

Expand Down
27 changes: 27 additions & 0 deletions oik-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ function oiksc_load_component( $plugin, $component_type ) {
*/
function oiksc_ajax_oiksc_create_api() {
do_action( "oik_loaded" );

// Enabling autoloading requires oik v3.0.0-beta.xxxx or higher

$lib_autoload = oik_require_lib( "oik-autoload" );
if ( $lib_autoload && !is_wp_error( $lib_autoload ) ) {
oik_autoload();
}
// User still has to be authorised to perform the request!
// So how do we check this?
//oiksc_create_api();
Expand Down Expand Up @@ -833,6 +840,12 @@ function oiksc_ajax_oiksc_create_api() {
function oiksc_ajax_oiksc_create_file() {

do_action( "oik_loaded" );

$lib_autoload = oik_require_lib( "oik-autoload" );
if ( $lib_autoload && !is_wp_error( $lib_autoload ) ) {
oik_autoload();
}

// User still has to be authorised to perform the request!
// So how do we check this?
//oiksc_create_api();
Expand Down Expand Up @@ -1265,13 +1278,27 @@ function oiksc_request( $request ) {
return( $request );
}


/**
* Implement "oik_query_autoload_classes" for oik-shortcodes
*
* Respond with our set of classes that can be autoloaded
*
* @param array $classes {@see OIK_Autoload::}
*/

function oiksc_oik_query_autoload_classes( $classes ) {
bw_trace2();
$classes[] = array( "class" => "oiksc_link_map"
, "plugin" => "oik-shortcodes"
, "path" => "classes"
, "file" => "classes/class-oiksc-link-map.php"
);
$classes[] = array( "class" => "oiksc_api_cache"
, "plugin" => "oik-shortcodes"
, "path" => "classes"
, "file" => "classes/class-oiksc-api-cache.php"
);
return( $classes );

}
Expand Down
13 changes: 6 additions & 7 deletions shortcodes/oik-api-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,11 +1616,11 @@ function oikai_handle_token_T_STRING( $key, $token, &$tokens, $doaction=true )
$tokens[$key][3] = oikai_link_to_php( $api_name );
$post_id = null;
} else {
$post = oikai_get_oik_apis_byname( $api_name );
if ( $post ) {
$post = bw_array_get( $post, 0, null );
if ( $post ) {
$post_id = $post->ID;
$post_ids = oikai_get_oik_api_byname( $api_name );
if ( $post_ids ) {
$post_id = bw_array_get( $post_ids, 0, null );
if ( $post_id ) {
//$post_id = $post;
//$value = $post_id;
if ( is_array( $tokens[$key] ) ) {
$tokens[$key][3] = retlink( null, oiksc_get_permalink( $post_id ), $tokens[$key][1], get_the_title( $post_id ) );
Expand All @@ -1632,8 +1632,7 @@ function oikai_handle_token_T_STRING( $key, $token, &$tokens, $doaction=true )
do_action( "oikai_handle_token_T_STRING", $post_id );
}
}
}
if ( !$post ) {
} else {
if ( $type == "user" ) {
$tokens[$key][3] = oikai_link_to_wordpress( $value );
} else {
Expand Down

0 comments on commit 99d62d2

Please sign in to comment.