Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1102757
D446.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Aug 19, 7:39 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Wed, Aug 20, 7:39 AM (7 h, 40 m)
Engine
blob
Format
Raw Data
Handle
714258
Attached To
D446: INP-1841 - Improve performance of System Log record removal code
D446.diff
View Options
Index: branches/5.2.x/core/units/logs/system_logs/system_log_eh.php
===================================================================
--- branches/5.2.x/core/units/logs/system_logs/system_log_eh.php
+++ branches/5.2.x/core/units/logs/system_logs/system_log_eh.php
@@ -89,32 +89,84 @@
}
/**
+ * Deletes all selected items.
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnMassDelete(kEvent $event)
+ {
+ $ids = $this->StoreSelectedIDs($event);
+ $this->clearSelectedIDs($event);
+
+ if ( !$ids ) {
+ return;
+ }
+
+ $this->deleteRecords(
+ $this->Application->getUnitOption($event->Prefix, 'IDField') . ' IN (' . implode(',', $ids) . ')'
+ );
+ }
+
+ /**
+ * Deletes all records from table
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnDeleteAll(kEvent $event)
+ {
+ $this->deleteRecords('TRUE');
+ }
+
+ /**
* [SCHEDULED TASK] Will remove old system logs
*
- * @param kEvent $event
+ * @param kEvent $event Event.
+ *
* @return void
- * @access protected
*/
protected function OnRotate(kEvent $event)
{
$rotation_interval = (int)$this->Application->ConfigValue('SystemLogRotationInterval');
+ // Forever.
if ( $rotation_interval === -1 ) {
- // forever
return;
}
- $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . '
- FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . '
- WHERE ' . TIMENOW . ' - LogTimestamp > ' . $rotation_interval . '
- LIMIT 0,50';
- $ids = $this->Conn->GetCol($sql);
-
- if ( $ids ) {
- /** @var kTempTablesHandler $temp_handler */
- $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event));
+ $this->deleteRecords('LogTimestamp < ' . strtotime('-' . $rotation_interval . ' seconds'));
+ }
+
+ /**
+ * Deletes records & connected records by a WHERE clause.
+ *
+ * @param string $where_clause Where clause.
+ *
+ * @return void
+ */
+ protected function deleteRecords($where_clause)
+ {
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');
+
+ $sql = 'SELECT ' . $id_field . '
+ FROM ' . $table_name . '
+ WHERE ' . $where_clause . '
+ LIMIT 0,500';
+
+ while ( true ) {
+ $ids = $this->Conn->GetCol($sql);
+
+ if ( !$ids ) {
+ break;
+ }
- $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids);
+ $sql = 'DELETE FROM ' . $table_name . '
+ WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')';
+ $this->Conn->Query($sql);
}
}
Event Timeline
Log In to Comment