mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Move clean functions into their respective classes
Uniformly name them gc()
This commit is contained in:
parent
cad1380737
commit
1069d54c85
17 changed files with 142 additions and 196 deletions
|
@ -118,7 +118,7 @@ switch ($_REQUEST['action']) {
|
||||||
} // end foreach songs
|
} // end foreach songs
|
||||||
|
|
||||||
// Clean out the old album
|
// Clean out the old album
|
||||||
$catalog->clean_albums();
|
Album::gc();
|
||||||
|
|
||||||
show_confirmation(T_('Album Updated'),'',Config::get('web_path') . '/admin/index.php');
|
show_confirmation(T_('Album Updated'),'',Config::get('web_path') . '/admin/index.php');
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ switch ($_REQUEST['action']) {
|
||||||
} // end foreach songs
|
} // end foreach songs
|
||||||
|
|
||||||
// Clean out the old artist(s)
|
// Clean out the old artist(s)
|
||||||
$catalog->clean_artists();
|
Artist::gc();
|
||||||
|
|
||||||
show_confirmation(T_('Artist Updated'),'',Config::get('web_path') . '/admin/index.php');
|
show_confirmation(T_('Artist Updated'),'',Config::get('web_path') . '/admin/index.php');
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,15 @@ class Album extends database_object {
|
||||||
|
|
||||||
} // construct_from_array
|
} // construct_from_array
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* Cleans out unused albums
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
Dba::write('DELETE FROM `album` USING `album` LEFT JOIN `song` ON `song`.`album` = `album`.`id` WHERE `song`.`id` IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build_cache
|
* build_cache
|
||||||
* This takes an array of object ids and caches all of their information
|
* This takes an array of object ids and caches all of their information
|
||||||
|
@ -305,7 +314,7 @@ class Album extends database_object {
|
||||||
Song::update_artist($artist,$song_id);
|
Song::update_artist($artist,$song_id);
|
||||||
}
|
}
|
||||||
$updated = 1;
|
$updated = 1;
|
||||||
Catalog::clean_artists();
|
Artist::gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
$album_id = Catalog::check_album($name,$year,$disk,$mbid);
|
$album_id = Catalog::check_album($name,$year,$disk,$mbid);
|
||||||
|
@ -317,7 +326,7 @@ class Album extends database_object {
|
||||||
}
|
}
|
||||||
$current_id = $album_id;
|
$current_id = $album_id;
|
||||||
$updated = 1;
|
$updated = 1;
|
||||||
Catalog::clean_albums();
|
self::gc();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updated) {
|
if ($updated) {
|
||||||
|
@ -326,7 +335,8 @@ class Album extends database_object {
|
||||||
Flag::add($song_id,'song','retag','Interface Album Update');
|
Flag::add($song_id,'song','retag','Interface Album Update');
|
||||||
Song::update_utime($song_id);
|
Song::update_utime($song_id);
|
||||||
} // foreach song of album
|
} // foreach song of album
|
||||||
Catalog::clean_stats();
|
Stats::gc();
|
||||||
|
Rating::gc();
|
||||||
} // if updated
|
} // if updated
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -552,10 +552,10 @@ class Art extends database_object {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean
|
* gc
|
||||||
* This cleans up art that no longer has a corresponding object
|
* This cleans up art that no longer has a corresponding object
|
||||||
*/
|
*/
|
||||||
public static function clean() {
|
public static function gc() {
|
||||||
// iterate over our types and delete the images
|
// iterate over our types and delete the images
|
||||||
foreach (array('album', 'artist') as $type) {
|
foreach (array('album', 'artist') as $type) {
|
||||||
$sql = "DELETE FROM `image` USING `image` LEFT JOIN `" .
|
$sql = "DELETE FROM `image` USING `image` LEFT JOIN `" .
|
||||||
|
@ -564,7 +564,7 @@ class Art extends database_object {
|
||||||
$type . "' AND `" . $type . "`.`id` IS NULL";
|
$type . "' AND `" . $type . "`.`id` IS NULL";
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
} // foreach
|
} // foreach
|
||||||
} // clean
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gather
|
* gather
|
||||||
|
|
|
@ -75,6 +75,15 @@ class Artist extends database_object {
|
||||||
|
|
||||||
} // construct_from_array
|
} // construct_from_array
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* This cleans out unused artists
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
Dba::write('DELETE FROM `artist` USING `artist` LEFT JOIN `song` ON `song`.`artist` = `artist`.`id` WHERE `song`.`id` IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this attempts to build a cache of the data from the passed albums all in one query
|
* this attempts to build a cache of the data from the passed albums all in one query
|
||||||
*/
|
*/
|
||||||
|
@ -285,7 +294,7 @@ class Artist extends database_object {
|
||||||
}
|
}
|
||||||
$updated = 1;
|
$updated = 1;
|
||||||
$current_id = $artist_id;
|
$current_id = $artist_id;
|
||||||
Catalog::clean_artists();
|
self::gc();
|
||||||
} // end if it changed
|
} // end if it changed
|
||||||
|
|
||||||
if ($updated) {
|
if ($updated) {
|
||||||
|
@ -293,7 +302,8 @@ class Artist extends database_object {
|
||||||
Flag::add($song_id,'song','retag','Interface Artist Update');
|
Flag::add($song_id,'song','retag','Interface Artist Update');
|
||||||
Song::update_utime($song_id);
|
Song::update_utime($song_id);
|
||||||
}
|
}
|
||||||
Catalog::clean_stats();
|
Stats::gc();
|
||||||
|
Rating::gc();
|
||||||
} // if updated
|
} // if updated
|
||||||
|
|
||||||
return $current_id;
|
return $current_id;
|
||||||
|
|
|
@ -1399,172 +1399,6 @@ class Catalog extends database_object {
|
||||||
|
|
||||||
} //_clean_chunk
|
} //_clean_chunk
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_tags
|
|
||||||
* This cleans out tag_maps that are not associated with a 'living' object
|
|
||||||
* and then cleans the tags that have no maps
|
|
||||||
*/
|
|
||||||
public static function clean_tags() {
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `song` ON `song`.`id`=`tag_map`.`object_id` " .
|
|
||||||
"WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `album` ON `album`.`id`=`tag_map`.`object_id` " .
|
|
||||||
"WHERE `tag_map`.`object_type`='album' AND `album`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `artist` ON `artist`.`id`=`tag_map`.`object_id` " .
|
|
||||||
"WHERE `tag_map`.`object_type`='artist' AND `artist`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " .
|
|
||||||
"WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Now nuke the tags themselves
|
|
||||||
$sql = "DELETE FROM `tag` USING `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
|
|
||||||
"WHERE `tag_map`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_tags
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_shoutbox
|
|
||||||
* This cleans out any shoutbox items that are now orphaned
|
|
||||||
*/
|
|
||||||
public static function clean_shoutbox() {
|
|
||||||
|
|
||||||
// Clean songs
|
|
||||||
$sql = "DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `song` ON `song`.`id`=`user_shout`.`object_id` " .
|
|
||||||
"WHERE `song`.`id` IS NULL AND `user_shout`.`object_type`='song'";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Clean albums
|
|
||||||
$sql = "DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `album` ON `album`.`id`=`user_shout`.`object_id` " .
|
|
||||||
"WHERE `album`.`id` IS NULL AND `user_shout`.`object_type`='album'";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Clean artists
|
|
||||||
$sql = "DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `artist` ON `artist`.`id`=`user_shout`.`object_id` " .
|
|
||||||
"WHERE `artist`.`id` IS NULL AND `user_shout`.`object_type`='artist'";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
|
|
||||||
} // clean_shoutbox
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_albums
|
|
||||||
*This function cleans out unused albums
|
|
||||||
*/
|
|
||||||
public static function clean_albums() {
|
|
||||||
|
|
||||||
/* Do a complex delete to get albums where there are no songs */
|
|
||||||
$sql = "DELETE FROM album USING album LEFT JOIN song ON song.album = album.id WHERE song.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_albums
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_flagged
|
|
||||||
* This functions cleans ou unused flagged items
|
|
||||||
*/
|
|
||||||
public static function clean_flagged() {
|
|
||||||
|
|
||||||
/* Do a complex delete to get flagged items where the songs are now gone */
|
|
||||||
$sql = "DELETE FROM flagged USING flagged LEFT JOIN song ON song.id = flagged.object_id WHERE song.id IS NULL AND object_type='song'";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_flagged
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_artists
|
|
||||||
* This function cleans out unused artists
|
|
||||||
*/
|
|
||||||
public static function clean_artists() {
|
|
||||||
|
|
||||||
/* Do a complex delete to get artists where there are no songs */
|
|
||||||
$sql = "DELETE FROM artist USING artist LEFT JOIN song ON song.artist = artist.id WHERE song.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} //clean_artists
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_playlists
|
|
||||||
* cleans out dead files from playlists
|
|
||||||
*/
|
|
||||||
public static function clean_playlists() {
|
|
||||||
|
|
||||||
/* Do a complex delete to get playlist songs where there are no songs */
|
|
||||||
$sql = "DELETE FROM `playlist_data` USING `playlist_data` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` " .
|
|
||||||
"WHERE `song`.`file` IS NULL AND `playlist_data`.`object_type`='song'";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Clear TMP Playlist information as well
|
|
||||||
$sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` LEFT JOIN `song` ON `tmp_playlist_data`.`object_id` = `song`.`id` " .
|
|
||||||
"WHERE `song`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_playlists
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_ext_info
|
|
||||||
* This function clears any ext_info that no longer has a parent
|
|
||||||
*/
|
|
||||||
public static function clean_ext_info() {
|
|
||||||
|
|
||||||
$sql = "DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` " .
|
|
||||||
"WHERE `song`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_ext_info
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clean_stats
|
|
||||||
* This functions removes stats for songs/albums that no longer exist
|
|
||||||
*/
|
|
||||||
public static function clean_stats() {
|
|
||||||
|
|
||||||
// Crazy SQL Mojo to remove stats where there are no songs
|
|
||||||
$sql = "DELETE FROM object_count USING object_count LEFT JOIN song ON song.id=object_count.object_id WHERE object_type='song' AND song.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Crazy SQL Mojo to remove stats where there are no albums
|
|
||||||
$sql = "DELETE FROM object_count USING object_count LEFT JOIN album ON album.id=object_count.object_id WHERE object_type='album' AND album.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Crazy SQL Mojo to remove stats where ther are no artists
|
|
||||||
$sql = "DELETE FROM object_count USING object_count LEFT JOIN artist ON artist.id=object_count.object_id WHERE object_type='artist' AND artist.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Delete the live_stream stat information
|
|
||||||
$sql = "DELETE FROM object_count USING object_count LEFT JOIN live_stream ON live_stream.id=object_count.object_id WHERE object_type='live_stream' AND live_stream.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Clean the stats
|
|
||||||
$sql = "DELETE FROM `object_count` USING `object_count` LEFT JOIN `video` ON `video`.`id`=`object_count`.`object_id` " .
|
|
||||||
"WHERE `object_count`.`object_type`='video' AND `video`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Delete Song Ratings information
|
|
||||||
$sql = "DELETE FROM rating USING rating LEFT JOIN song ON song.id=rating.object_id WHERE object_type='song' AND song.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Delete Album Rating Information
|
|
||||||
$sql = "DELETE FROM rating USING rating LEFT JOIN album ON album.id=rating.object_id WHERE object_type='album' AND album.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Delete Artist Rating Information
|
|
||||||
$sql = "DELETE FROM rating USING rating LEFT JOIN artist ON artist.id=rating.object_id WHERE object_type='artist' AND artist.id IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
// Delete the Video Rating Informations
|
|
||||||
$sql = "DELETE FROM `rating` USING `rating` LEFT JOIN `video` ON `video`.`id`=`rating`.`object_id` " .
|
|
||||||
"WHERE `rating`.`object_type`='video' AND `video`.`id` IS NULL";
|
|
||||||
$db_results = Dba::write($sql);
|
|
||||||
|
|
||||||
} // clean_stats
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* verify_catalog
|
* verify_catalog
|
||||||
* This function compares the DB's information with the ID3 tags
|
* This function compares the DB's information with the ID3 tags
|
||||||
|
@ -1675,15 +1509,17 @@ class Catalog extends database_object {
|
||||||
public static function clean() {
|
public static function clean() {
|
||||||
|
|
||||||
debug_event('catalog', 'Database cleanup started', 5, 'ampache-catalog');
|
debug_event('catalog', 'Database cleanup started', 5, 'ampache-catalog');
|
||||||
self::clean_albums();
|
Song::gc();
|
||||||
self::clean_artists();
|
Album::gc();
|
||||||
Art::clean();
|
Artist::gc();
|
||||||
self::clean_flagged();
|
Art::gc();
|
||||||
self::clean_stats();
|
Flag::gc();
|
||||||
self::clean_ext_info();
|
Stats::gc();
|
||||||
self::clean_playlists();
|
Rating::gc();
|
||||||
self::clean_shoutbox();
|
Playlist::gc();
|
||||||
self::clean_tags();
|
tmpPlaylist::gc();
|
||||||
|
shoutBox::gc();
|
||||||
|
Tag::gc();
|
||||||
debug_event('catalog', 'Database cleanup ended', 5, 'ampache-catalog');
|
debug_event('catalog', 'Database cleanup ended', 5, 'ampache-catalog');
|
||||||
|
|
||||||
} // clean
|
} // clean
|
||||||
|
|
|
@ -58,6 +58,15 @@ class Flag extends database_object {
|
||||||
|
|
||||||
} // Constructor
|
} // Constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* This cleans out unused flagged items
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
Dba::write("DELETE FROM `flagged` USING `flagged` LEFT JOIN `song` ON `song`.`id` = `flagged`.`object_id` WHERE `song`.`id` IS NULL AND `object_type` = 'song'");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build_cache
|
* build_cache
|
||||||
* This takes an array of ids and builds up a nice little cache
|
* This takes an array of ids and builds up a nice little cache
|
||||||
|
|
|
@ -51,6 +51,15 @@ class Playlist extends playlist_object {
|
||||||
|
|
||||||
} // Playlist
|
} // Playlist
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* Clean dead items out of playlists
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
Dba::write("DELETE FROM `playlist_data` USING `playlist_data` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` WHERE `song`.`file` IS NULL AND `playlist_data`.`object_type`='song'");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build_cache
|
* build_cache
|
||||||
* This is what builds the cache from the objects
|
* This is what builds the cache from the objects
|
||||||
|
|
|
@ -48,6 +48,17 @@ class Rating extends database_object {
|
||||||
|
|
||||||
} // Constructor
|
} // Constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* Remove ratings for items that no longer exist.
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
foreach(array('song', 'album', 'artist', 'video') as $object_type) {
|
||||||
|
Dba::write("DELETE FROM `rating` USING `rating` LEFT JOIN `$object_type` ON `$object_type`.`id` = `rating`.`object_type` WHERE `object_type` = '$object_type` AND `$object_type`.`id` IS NULL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build_cache
|
* build_cache
|
||||||
* This attempts to get everything we'll need for this page load in a
|
* This attempts to get everything we'll need for this page load in a
|
||||||
|
|
|
@ -59,6 +59,17 @@ class shoutBox {
|
||||||
|
|
||||||
} // _get_info
|
} // _get_info
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* Cleans out orphaned shoutbox items
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
foreach(array('song', 'album', 'artist') as $object_type) {
|
||||||
|
Dba::write("DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `$object_type` ON `$object_type`.`id` = `user_shout`.`object_id` WHERE `$object_type`.`id` IS NULL AND `user_shout`.`object_type` = '$object_type'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_top
|
* get_top
|
||||||
* This returns the top user_shouts, shoutbox objects are always shown regardless and count against the total
|
* This returns the top user_shouts, shoutbox objects are always shown regardless and count against the total
|
||||||
|
|
|
@ -74,6 +74,15 @@ class Song extends database_object implements media {
|
||||||
|
|
||||||
} // constructor
|
} // constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* Cleans up the song_data table
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
Dba::write('DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` WHERE `song`.`id` IS NULL');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build_cache
|
* build_cache
|
||||||
*
|
*
|
||||||
|
|
|
@ -55,7 +55,18 @@ class Stats {
|
||||||
*/
|
*/
|
||||||
public static function clear() {
|
public static function clear() {
|
||||||
Dba::write('TRUNCATE `object_count`');
|
Dba::write('TRUNCATE `object_count`');
|
||||||
Dba::write('UPDATE `song` SET `played` = 0';
|
Dba::write('UPDATE `song` SET `played` = 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* This removes stats for things that no longer exist.
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
foreach(array('song', 'album', 'artist', 'live_stream', 'video') as $object_type) {
|
||||||
|
Dba::write("DELETE FROM `object_count` USING `object_count` LEFT JOIN `$object_type` ON `$object_type`.`id` = `object_count`.`object_id` WHERE `object_type` = '$object_type' AND `$object_type`.`id` IS NULL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -101,19 +101,19 @@ class Stream {
|
||||||
} // session_exists
|
} // session_exists
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gc_session
|
* gc
|
||||||
* This function performes the garbage collection stuff, run on extend
|
* This function performes the garbage collection stuff, run on extend
|
||||||
* and on now playing refresh.
|
* and on now playing refresh.
|
||||||
*/
|
*/
|
||||||
public static function gc_session() {
|
public static function gc() {
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'";
|
$sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'";
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
Stream_Playlist::clean();
|
Stream_Playlist::gc();
|
||||||
|
|
||||||
} // gc_session
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* extend_session
|
* extend_session
|
||||||
|
@ -132,7 +132,7 @@ class Stream {
|
||||||
"WHERE `id`='$sid'";
|
"WHERE `id`='$sid'";
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
self::gc_session();
|
self::gc();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Stream_Playlist {
|
||||||
return Dba::write($sql);
|
return Dba::write($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function clean() {
|
public static function gc() {
|
||||||
$sql = 'DELETE FROM `stream_playlist` ' .
|
$sql = 'DELETE FROM `stream_playlist` ' .
|
||||||
'USING `stream_playlist` LEFT JOIN `session_stream` ' .
|
'USING `stream_playlist` LEFT JOIN `session_stream` ' .
|
||||||
'ON `session_stream`.`id`=`stream_playlist`.`sid` ' .
|
'ON `session_stream`.`id`=`stream_playlist`.`sid` ' .
|
||||||
|
|
|
@ -269,6 +269,35 @@ class Tag extends database_object {
|
||||||
|
|
||||||
} // add_tag_map
|
} // add_tag_map
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gc
|
||||||
|
*
|
||||||
|
* This cleans out tag_maps that are obsolete and then removes tags that
|
||||||
|
* have no maps.
|
||||||
|
*/
|
||||||
|
public static function gc() {
|
||||||
|
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `song` ON `song`.`id`=`tag_map`.`object_id` " .
|
||||||
|
"WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL";
|
||||||
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `album` ON `album`.`id`=`tag_map`.`object_id` " .
|
||||||
|
"WHERE `tag_map`.`object_type`='album' AND `album`.`id` IS NULL";
|
||||||
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `artist` ON `artist`.`id`=`tag_map`.`object_id` " .
|
||||||
|
"WHERE `tag_map`.`object_type`='artist' AND `artist`.`id` IS NULL";
|
||||||
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
|
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " .
|
||||||
|
"WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL";
|
||||||
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
|
// Now nuke the tags themselves
|
||||||
|
$sql = "DELETE FROM `tag` USING `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
|
||||||
|
"WHERE `tag_map`.`id` IS NULL";
|
||||||
|
$db_results = Dba::write($sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tag_exists
|
* tag_exists
|
||||||
* This checks to see if a tag exists, this has nothing to do with objects or maps
|
* This checks to see if a tag exists, this has nothing to do with objects or maps
|
||||||
|
|
|
@ -278,12 +278,13 @@ class tmpPlaylist extends database_object {
|
||||||
} // session_clean
|
} // session_clean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clean
|
* gc
|
||||||
* This cleans up old data
|
* This cleans up old data
|
||||||
*/
|
*/
|
||||||
public static function clean() {
|
public static function gc() {
|
||||||
self::prune_playlists();
|
self::prune_playlists();
|
||||||
self::prune_tracks();
|
self::prune_tracks();
|
||||||
|
Dba::write("DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` LEFT JOIN `song` ON `tmp_playlist_data`.`object_id` = `song`.`id` WHERE `song`.`id` IS NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -143,7 +143,7 @@ class vauth {
|
||||||
|
|
||||||
// Also clean up things that use sessions as keys
|
// Also clean up things that use sessions as keys
|
||||||
Query::clean();
|
Query::clean();
|
||||||
tmpPlaylist::clean();
|
tmpPlaylist::gc();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -759,7 +759,7 @@ function print_bool($value) {
|
||||||
*/
|
*/
|
||||||
function show_now_playing() {
|
function show_now_playing() {
|
||||||
|
|
||||||
Stream::gc_session();
|
Stream::gc();
|
||||||
Stream::gc_now_playing();
|
Stream::gc_now_playing();
|
||||||
|
|
||||||
$web_path = Config::get('web_path');
|
$web_path = Config::get('web_path');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue