diff --git a/resources/sql/autopatches/20140617.daemonlog.sql b/resources/sql/autopatches/20140617.daemonlog.sql new file mode 100644 index 0000000000..5904af039c --- /dev/null +++ b/resources/sql/autopatches/20140617.daemonlog.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_daemon.daemon_log + ADD KEY (dateCreated); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fab6d43807..cd8ff2e05c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1454,6 +1454,7 @@ phutil_register_library_map(array( 'PhabricatorDaemonEventListener' => 'applications/daemon/event/PhabricatorDaemonEventListener.php', 'PhabricatorDaemonLog' => 'applications/daemon/storage/PhabricatorDaemonLog.php', 'PhabricatorDaemonLogEvent' => 'applications/daemon/storage/PhabricatorDaemonLogEvent.php', + 'PhabricatorDaemonLogEventGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php', 'PhabricatorDaemonLogEventViewController' => 'applications/daemon/controller/PhabricatorDaemonLogEventViewController.php', 'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php', 'PhabricatorDaemonLogGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php', @@ -4265,6 +4266,7 @@ phutil_register_library_map(array( 1 => 'PhabricatorPolicyInterface', ), 'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO', + 'PhabricatorDaemonLogEventGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorDaemonLogEventViewController' => 'PhabricatorDaemonController', 'PhabricatorDaemonLogEventsView' => 'AphrontView', 'PhabricatorDaemonLogGarbageCollector' => 'PhabricatorGarbageCollector', diff --git a/src/applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php new file mode 100644 index 0000000000..c5a502c599 --- /dev/null +++ b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogEventGarbageCollector.php @@ -0,0 +1,24 @@ +establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE epoch < %d LIMIT 100', + $table->getTableName(), + time() - $ttl); + + return ($conn_w->getAffectedRows() == 100); + } + +} diff --git a/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php index 22a11523ae..bd8b92bf92 100644 --- a/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php +++ b/src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php @@ -9,14 +9,15 @@ final class PhabricatorDaemonLogGarbageCollector return false; } - $table = new PhabricatorDaemonLogEvent(); + $table = new PhabricatorDaemonLog(); $conn_w = $table->establishConnection('w'); queryfx( $conn_w, - 'DELETE FROM %T WHERE epoch < %d LIMIT 100', + 'DELETE FROM %T WHERE dateCreated < %d AND status != %s LIMIT 100', $table->getTableName(), - time() - $ttl); + time() - $ttl, + PhabricatorDaemonLog::STATUS_RUNNING); return ($conn_w->getAffectedRows() == 100); }