dba functions in poller / avoiding SQL errors in conversation / dbclean is better

This commit is contained in:
Michael 2017-05-12 16:09:25 +00:00
parent acd9f453d7
commit 377fe31907
3 changed files with 37 additions and 36 deletions

View file

@ -18,13 +18,11 @@ function dbclean_run(&$argv, &$argc) {
} }
if ($stage == 0) { if ($stage == 0) {
proc_run(PRIORITY_LOW, 'include/dbclean.php', 1); for ($i = 1; $i <= 7; $i++) {
proc_run(PRIORITY_LOW, 'include/dbclean.php', 2); if (!Config::get('system', 'finished-dbclean-'.$i)) {
proc_run(PRIORITY_LOW, 'include/dbclean.php', 3); proc_run(PRIORITY_LOW, 'include/dbclean.php', $i);
proc_run(PRIORITY_LOW, 'include/dbclean.php', 4); }
proc_run(PRIORITY_LOW, 'include/dbclean.php', 5); }
proc_run(PRIORITY_LOW, 'include/dbclean.php', 6);
proc_run(PRIORITY_LOW, 'include/dbclean.php', 7);
} else { } else {
remove_orphans($stage); remove_orphans($stage);
} }
@ -54,6 +52,9 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No global item orphans found"); logger("No global item orphans found");
// We will eventually set this value when we found a good way to delete these items in another way.
// Config::set('system', 'finished-dbclean-1', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." old global item entries from item table without user copy"); logger("Done deleting ".$count." old global item entries from item table without user copy");
@ -68,6 +69,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No item orphans without parents found"); logger("No item orphans without parents found");
Config::set('system', 'finished-dbclean-2', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." items without parents"); logger("Done deleting ".$count." items without parents");
@ -82,6 +84,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No thread orphans found"); logger("No thread orphans found");
Config::set('system', 'finished-dbclean-3', true);
} }
dba::close($r); dba::close($r);
@ -97,6 +100,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No notify orphans found"); logger("No notify orphans found");
Config::set('system', 'finished-dbclean-4', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from notify table"); logger("Done deleting ".$count." orphaned data from notify table");
@ -111,6 +115,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No notify-threads orphans found"); logger("No notify-threads orphans found");
Config::set('system', 'finished-dbclean-5', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from notify-threads table"); logger("Done deleting ".$count." orphaned data from notify-threads table");
@ -125,6 +130,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No sign orphans found"); logger("No sign orphans found");
Config::set('system', 'finished-dbclean-6', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from sign table"); logger("Done deleting ".$count." orphaned data from sign table");
@ -139,6 +145,7 @@ function remove_orphans($stage = 0) {
} }
} else { } else {
logger("No term orphans found"); logger("No term orphans found");
Config::set('system', 'finished-dbclean-7', true);
} }
dba::close($r); dba::close($r);
logger("Done deleting ".$count." orphaned data from term table"); logger("Done deleting ".$count." orphaned data from term table");

View file

@ -501,6 +501,20 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
} }
} }
if ($notify) {
$guid_prefix = "";
} elseif ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "")) {
$arr['guid'] = uri_to_guid($arr['plink']);
} elseif ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) {
$arr['guid'] = uri_to_guid($arr['uri']);
} else {
$parsed = parse_url($arr["author-link"]);
$guid_prefix = hash("crc32", $parsed["host"]);
}
$arr['guid'] = ((x($arr, 'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix));
$arr['uri'] = ((x($arr, 'uri')) ? notags(trim($arr['uri'])) : item_new_uri($a->get_hostname(), $uid, $arr['guid']));
// Store conversation data // Store conversation data
$arr = store_conversation($arr); $arr = store_conversation($arr);
@ -585,20 +599,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
item_add_language_opt($arr); item_add_language_opt($arr);
if ($notify) {
$guid_prefix = "";
} elseif ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "")) {
$arr['guid'] = uri_to_guid($arr['plink']);
} elseif ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) {
$arr['guid'] = uri_to_guid($arr['uri']);
} else {
$parsed = parse_url($arr["author-link"]);
$guid_prefix = hash("crc32", $parsed["host"]);
}
$arr['wall'] = ((x($arr, 'wall')) ? intval($arr['wall']) : 0); $arr['wall'] = ((x($arr, 'wall')) ? intval($arr['wall']) : 0);
$arr['guid'] = ((x($arr, 'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix));
$arr['uri'] = ((x($arr, 'uri')) ? notags(trim($arr['uri'])) : item_new_uri($a->get_hostname(), $uid, $arr['guid']));
$arr['extid'] = ((x($arr, 'extid')) ? notags(trim($arr['extid'])) : ''); $arr['extid'] = ((x($arr, 'extid')) ? notags(trim($arr['extid'])) : '');
$arr['author-name'] = ((x($arr, 'author-name')) ? trim($arr['author-name']) : ''); $arr['author-name'] = ((x($arr, 'author-name')) ? trim($arr['author-name']) : '');
$arr['author-link'] = ((x($arr, 'author-link')) ? notags(trim($arr['author-link'])) : ''); $arr['author-link'] = ((x($arr, 'author-link')) ? notags(trim($arr['author-link'])) : '');

View file

@ -121,12 +121,8 @@ function poller_execute($queue) {
return false; return false;
} }
$upd = q("UPDATE `workerqueue` SET `executed` = '%s', `pid` = %d WHERE `id` = %d AND `pid` = 0", if (!dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid),
dbesc(datetime_convert()), array('id' => $queue["id"], 'pid' => 0))) {
intval($mypid),
intval($queue["id"]));
if (!$upd) {
logger("Couldn't update queue entry ".$queue["id"]." - skip this execution", LOGGER_DEBUG); logger("Couldn't update queue entry ".$queue["id"]." - skip this execution", LOGGER_DEBUG);
dba::commit(); dba::commit();
return true; return true;
@ -156,7 +152,7 @@ function poller_execute($queue) {
if (!validate_include($include)) { if (!validate_include($include)) {
logger("Include file ".$argv[0]." is not valid!"); logger("Include file ".$argv[0]." is not valid!");
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($queue["id"])); dba::delete('workerqueue', array('id' => $queue["id"]));
return true; return true;
} }
@ -168,7 +164,7 @@ function poller_execute($queue) {
poller_exec_function($queue, $funcname, $argv); poller_exec_function($queue, $funcname, $argv);
q("DELETE FROM `workerqueue` WHERE `id` = %d", intval($queue["id"])); dba::delete('workerqueue', array('id' => $queue["id"]));
} else { } else {
logger("Function ".$funcname." does not exist"); logger("Function ".$funcname." does not exist");
} }
@ -376,8 +372,8 @@ function poller_kill_stale_workers() {
foreach ($r AS $pid) { foreach ($r AS $pid) {
if (!posix_kill($pid["pid"], 0)) { if (!posix_kill($pid["pid"], 0)) {
q("UPDATE `workerqueue` SET `executed` = '%s', `pid` = 0 WHERE `pid` = %d", dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0),
dbesc(NULL_DATE), intval($pid["pid"])); array('pid' => $pid["pid"]));
} else { } else {
// Kill long running processes // Kill long running processes
@ -401,12 +397,9 @@ function poller_kill_stale_workers() {
// We killed the stale process. // We killed the stale process.
// To avoid a blocking situation we reschedule the process at the beginning of the queue. // To avoid a blocking situation we reschedule the process at the beginning of the queue.
// Additionally we are lowering the priority. // Additionally we are lowering the priority.
q("UPDATE `workerqueue` SET `executed` = '%s', `created` = '%s', dba::update('workerqueue',
`priority` = %d, `pid` = 0 WHERE `pid` = %d", array('executed' => NULL_DATE, 'created' => datetime_convert(), 'priority' => PRIORITY_NEGLIGIBLE, 'pid' => 0),
dbesc(NULL_DATE), array('pid' => $pid["pid"]));
dbesc(datetime_convert()),
intval(PRIORITY_NEGLIGIBLE),
intval($pid["pid"]));
} else { } else {
logger("Worker process ".$pid["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG); logger("Worker process ".$pid["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
} }