]> git.mxchange.org Git - friendica.git/commitdiff
Remove orphaned data
authorMichael Vogel <ike@pirati.ca>
Wed, 19 Oct 2016 21:06:37 +0000 (21:06 +0000)
committerMichael Vogel <ike@pirati.ca>
Wed, 19 Oct 2016 21:06:37 +0000 (21:06 +0000)
include/cron.php
include/dbclean.php [new file with mode: 0644]
mod/display.php

index 0669f24a1ea9bebf1420a20effaa5626a64409e7..6913588db89d61fccea91016de129754c2fba37c 100644 (file)
@@ -125,6 +125,8 @@ function cron_run(&$argv, &$argc){
                set_config('system','last_expire_day',$d2);
 
                proc_run(PRIORITY_LOW,'include/expire.php');
+
+               proc_run(PRIORITY_LOW,'include/dbclean.php');
        }
 
        // Clear cache entries
@@ -355,10 +357,10 @@ function cron_clear_cache(&$a) {
        }
 
        // Delete the cached OEmbed entries that are older than one year
-       q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 1 YEAR");
+       q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 3 MONTH");
 
        // Delete the cached "parse_url" entries that are older than one year
-       q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 1 YEAR");
+       q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 3 MONTH");
 
        // Maximum table size in megabyte
        $max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
diff --git a/include/dbclean.php b/include/dbclean.php
new file mode 100644 (file)
index 0000000..8ec9c1d
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+require_once("boot.php");
+
+global $a, $db;
+
+if(is_null($a))
+       $a = new App;
+
+if(is_null($db)) {
+       @include(".htconfig.php");
+       require_once("include/dba.php");
+       $db = new dba($db_host, $db_user, $db_pass, $db_data);
+       unset($db_host, $db_user, $db_pass, $db_data);
+}
+
+load_config('config');
+load_config('system');
+
+update_shadow_copy();
+killme();
+
+function remove_orphans() {
+
+       logger("Deleting orphaned data from thread table");
+       q("DELETE FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`)");
+
+       logger("Deleting orphaned data from notify table");
+       q("DELETE FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`)");
+
+       logger("Deleting orphaned data from sign table");
+       q("DELETE FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`)");
+
+       logger("Deleting orphaned data from term table");
+       q("DELETE FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`)");
+
+       logger("Done deleting orphaned data from tables");
+}
+?>
index 01a66c93b6e01e3b13583849a0694f1e7b98911a..b21c2810caa4134b407ebadf15daef947b86e3d6 100644 (file)
@@ -27,7 +27,7 @@ function display_init(&$a) {
 
                // Or is it anywhere on the server?
                if ($nick == "") {
-                       $r = qu("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
+                       $r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
                                `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
                                FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
                                WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
@@ -35,7 +35,6 @@ function display_init(&$a) {
                                        AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
                                        AND NOT `item`.`private` AND NOT `user`.`hidewall`
                                        AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
-                               //      AND NOT `item`.`private` AND `item`.`wall`
                        if (count($r)) {
                                $nick = $r[0]["nickname"];
                                $itemuid = $r[0]["uid"];
@@ -51,7 +50,6 @@ function display_init(&$a) {
                                        AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
                                        AND NOT `item`.`private` AND `item`.`uid` = 0
                                        AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
-                               //      AND NOT `item`.`private` AND `item`.`wall`
                }
                if (count($r)) {
                        if ($r[0]["id"] != $r[0]["parent"])