functions.php
changeset 2 860ba7141641
parent 0 c63de9eb7045
child 4 cde92f6ec29f
--- a/functions.php	Sun Mar 23 15:24:06 2008 -0400
+++ b/functions.php	Sun Mar 23 20:24:33 2008 -0400
@@ -68,12 +68,21 @@
  * Rebuilds the copy of the playlist in RAM
  */
 
+$playlist_last_md5 = '';
+
 function rebuild_playlist()
 {
   // import what we need
   global $homedir, $playlist;
   // sync and load the playlist file
   $playlist_file = dcop_action('playlist', 'saveCurrentPlaylist');
+  // check MD5 - if it's not changed, exit to save CPU cycles
+  global $playlist_last_md5;
+  if ( $playlist_last_md5 == @md5_file($playlist_file) )
+  {
+    return true;
+  }
+  $playlist_last_md5 = @md5_file($playlist_file);
   // start XML parser
   try
   {
@@ -97,7 +106,8 @@
         'title'  => strval($child->Title),
         'artist' => strval($child->Artist),
         'album'  => strval($child->Album),
-        'length' => seconds_to_str(intval($child->Length))
+        'length' => seconds_to_str(intval($child->Length)),
+        'length_int' => intval($child->Length)
       );
     $playlist[] = $item;
   }