Skip to content

Commit

Permalink
Organizing memcache flow
Browse files Browse the repository at this point in the history
  • Loading branch information
pdweinstein committed Aug 13, 2019
1 parent 6946a13 commit 5202838
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
83 changes: 39 additions & 44 deletions lib/pre.php
Expand Up @@ -12,25 +12,22 @@
$memcache = new Memcache;
$memcache->addServer( $mhost, $mport );

if ( $posts = $memcache->get( 'latest_pdw' )) {
if ( $posts = $memcache->get( 'latest' )) {

$posts = $memcache->get( 'latest' );
$githubEvents = $memcache->get( 'github' );
$recent = $memcache->get( 'flickr' );
$recent = $memcache->get( 'flickr_recent' );
$info = $memcache->get( 'flickr_info' );
$books = $memcache->get( 'goodreads' );
$instaData = $memcache->get( 'instagram' );
$tweets = $memcache->get( 'tweets' );

// Pull our winner
$latest = key( $posts );
$latestDate = gmdate( "M d Y", $posts[$latest] );

}

}

if (( $location == 'local' ) OR
( !$posts = $memcache->get( 'latest_pdw' ))) {
( !$posts = $memcache->get( 'latest' ))) {

//$seti = new RPC;

Expand All @@ -56,51 +53,49 @@
$instaObj = $elsewhere->getInstaPosts( $instaToken, 1 );
$tweets = json_decode( $twitter->setGetfield( $getfield )->buildOauth( $twitterURL, $requestMethod )->performRequest() );

// GitHub Last Post
$GHrecent = $githubEvents[0];
$posts['github'] = strtotime( $GHrecent->created_at );
$feed['github'] = $GHrecent;

// Flickr Last Post
$posts['flickr'] = $info['photo']['dateuploaded'];
$feed['flickr'] = $info;

// Goodreads. No date for post (start/end reading dates)
if( $location != 'local' ) {

// Instagram Last Post
$instaData = $instaObj->{'data'};
$posts['instagram'] = $instaData[0]->{'created_time'};
$feed['instagram'] = $instaData;
$memcache->set( 'latest', $latest, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'github', $githubEvents, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'flickr_recent', $recent, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'flickr_info', $info, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'goodreads', $books, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'instagram', $instaObj, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'twitter', $tweets, MEMCACHE_COMPRESSED, 3600 );

}

// Twitter Last Post
$tweet = $tweets[0];
$posts['twitter'] = strtotime( $tweet->created_at );
$feed['twitter'] = $tweets;

// Sort Array of Unix Timestamps
arsort( $posts );
}

// Reset our pointer to the top of the array
reset( $posts );
// GitHub Last Post
$GHrecent = $githubEvents[0];
$posts['github'] = strtotime( $GHrecent->created_at );
$feed['github'] = $GHrecent;

// Pull our winner
$latest = key( $posts );
$latestDate = gmdate( "M d Y", $posts[$latest] );
// Flickr Last Post
$posts['flickr'] = $info['photo']['dateuploaded'];
$feed['flickr'] = $info;

if( $location != 'local' ) {
// Goodreads. No date for post (start/end reading dates)

$memcache->set( 'latest', $latest );
$memcache->set( 'github', $githubEvents );
$memcache->set( 'flickr_recent', $recent );
$memcache->set( 'flickr_info', $info );
// $memcache->set( 'goodreads', $books, MEMCACHE_COMPRESSED, 3600 );
$memcache->set( 'instagram', $instaObj );
$memcache->set( 'twitter', $tweets );

}
// Instagram Last Post
$instaData = $instaObj->{'data'};
$posts['instagram'] = $instaData[0]->{'created_time'};
$feed['instagram'] = $instaData;

}
// Twitter Last Post
$tweet = $tweets[0];
$posts['twitter'] = strtotime( $tweet->created_at );
$feed['twitter'] = $tweets;

// Sort Array of Unix Timestamps
arsort( $posts );

// Reset our pointer to the top of the array
reset( $posts );

// Pull our winner
$latest = key( $posts );
$latestDate = gmdate( "M d Y", $posts[$latest] );

?>
5 changes: 2 additions & 3 deletions www/index.php
Expand Up @@ -3,13 +3,12 @@
include_once( '../config.php' );
include_once( '../lib/include.php' );
include_once( '../lib/pre.php' );

/*
if ( $location != 'local' ) {
$memcache = new Memcache;
}
/*
//$seti = new RPC;
$seti = new RPC;
$goodReads = new goodReads( $goodreads_token, $goodreads_user_id, $goodreadsOptions, true);
$books = $goodReads->getShelf();
Expand Down

0 comments on commit 5202838

Please sign in to comment.