Update in chunks
This commit is contained in:
parent
5b9239b341
commit
e07b73f560
|
@ -460,92 +460,85 @@ class Post
|
||||||
$update_fields = DBStructure::getFieldsForTable('post-content', $fields);
|
$update_fields = DBStructure::getFieldsForTable('post-content', $fields);
|
||||||
if (!empty($update_fields)) {
|
if (!empty($update_fields)) {
|
||||||
$affected_count = 0;
|
$affected_count = 0;
|
||||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
$posts = DBA::select('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||||
$uriids = array_column($rows, 'uri-id');
|
while ($rows = DBA::toArray($posts, false, 100)) {
|
||||||
$elements = $uriids;
|
$uriids = array_column($rows, 'uri-id');
|
||||||
while (!empty($elements)) {
|
if (!DBA::update('post-content', $update_fields, ['uri-id' => $uriids])) {
|
||||||
$segment = array_splice($elements, 0, 100);
|
|
||||||
if (!DBA::update('post-content', $update_fields, ['uri-id' => $segment])) {
|
|
||||||
DBA::rollback();
|
DBA::rollback();
|
||||||
Logger::notice('Updating post-content failed', ['fields' => $update_fields, 'condition' => $condition]);
|
Logger::notice('Updating post-content failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$affected_count += DBA::affectedRows();
|
$affected_count += DBA::affectedRows();
|
||||||
}
|
}
|
||||||
|
DBA::close($posts);
|
||||||
$affected = max($affected, $affected_count);
|
$affected = max($affected, $affected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_fields = DBStructure::getFieldsForTable('post', $fields);
|
$update_fields = DBStructure::getFieldsForTable('post', $fields);
|
||||||
if (!empty($update_fields)) {
|
if (!empty($update_fields)) {
|
||||||
$affected_count = 0;
|
$affected_count = 0;
|
||||||
if (empty($uriids)) {
|
$posts = DBA::select('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
while ($rows = DBA::toArray($posts, false, 100)) {
|
||||||
$uriids = array_column($rows, 'uri-id');
|
$uriids = array_column($rows, 'uri-id');
|
||||||
}
|
if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) {
|
||||||
$elements = $uriids;
|
|
||||||
while (!empty($elements)) {
|
|
||||||
$segment = array_splice($elements, 0, 100);
|
|
||||||
if (!DBA::update('post', $update_fields, ['uri-id' => $segment])) {
|
|
||||||
DBA::rollback();
|
DBA::rollback();
|
||||||
Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]);
|
Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$affected_count += DBA::affectedRows();
|
$affected_count += DBA::affectedRows();
|
||||||
}
|
}
|
||||||
|
DBA::close($posts);
|
||||||
$affected = max($affected, $affected_count);
|
$affected = max($affected, $affected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_fields = Post\DeliveryData::extractFields($fields);
|
$update_fields = Post\DeliveryData::extractFields($fields);
|
||||||
if (!empty($update_fields)) {
|
if (!empty($update_fields)) {
|
||||||
$affected_count = 0;
|
$affected_count = 0;
|
||||||
if (empty($uriids)) {
|
$posts = DBA::select('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
while ($rows = DBA::toArray($posts, false, 100)) {
|
||||||
$uriids = array_column($rows, 'uri-id');
|
$uriids = array_column($rows, 'uri-id');
|
||||||
}
|
if (!DBA::update('post-delivery-data', $update_fields, ['uri-id' => $uriids])) {
|
||||||
$elements = $uriids;
|
|
||||||
while (!empty($elements)) {
|
|
||||||
$segment = array_splice($elements, 0, 100);
|
|
||||||
if (!DBA::update('post-delivery-data', $update_fields, ['uri-id' => $segment])) {
|
|
||||||
DBA::rollback();
|
DBA::rollback();
|
||||||
Logger::notice('Updating post-delivery-data failed', ['fields' => $update_fields, 'condition' => $condition]);
|
Logger::notice('Updating post-delivery-data failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$affected_count += DBA::affectedRows();
|
$affected_count += DBA::affectedRows();
|
||||||
}
|
}
|
||||||
|
DBA::close($posts);
|
||||||
$affected = max($affected, $affected_count);
|
$affected = max($affected, $affected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
|
$update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
|
||||||
if (!empty($update_fields)) {
|
if (!empty($update_fields)) {
|
||||||
$affected_count = 0;
|
$affected_count = 0;
|
||||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]);
|
$posts = DBA::select('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]);
|
||||||
$uriids = array_column($rows, 'uri-id');
|
while ($rows = DBA::toArray($posts, false, 100)) {
|
||||||
while (!empty($uriids)) {
|
$uriids = array_column($rows, 'uri-id');
|
||||||
$segment = array_splice($uriids, 0, 100);
|
if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) {
|
||||||
if (!DBA::update('post-thread', $update_fields, ['uri-id' => $segment])) {
|
|
||||||
DBA::rollback();
|
DBA::rollback();
|
||||||
Logger::notice('Updating post-thread failed', ['fields' => $update_fields, 'condition' => $condition]);
|
Logger::notice('Updating post-thread failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$affected_count += DBA::affectedRows();
|
$affected_count += DBA::affectedRows();
|
||||||
}
|
}
|
||||||
|
DBA::close($posts);
|
||||||
$affected = max($affected, $affected_count);
|
$affected = max($affected, $affected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$update_fields = DBStructure::getFieldsForTable('post-thread-user', $fields);
|
$update_fields = DBStructure::getFieldsForTable('post-thread-user', $fields);
|
||||||
if (!empty($update_fields)) {
|
if (!empty($update_fields)) {
|
||||||
$affected_count = 0;
|
$affected_count = 0;
|
||||||
$rows = DBA::selectToArray('post-view', ['post-user-id'], $thread_condition);
|
$posts = DBA::select('post-view', ['post-user-id'], $thread_condition);
|
||||||
$thread_puids = array_column($rows, 'post-user-id');
|
while ($rows = DBA::toArray($posts, false, 100)) {
|
||||||
while (!empty($thread_puids)) {
|
$thread_puids = array_column($rows, 'post-user-id');
|
||||||
$segment = array_splice($thread_puids, 0, 100);
|
if (!DBA::update('post-thread-user', $update_fields, ['post-user-id' => $thread_puids])) {
|
||||||
if (!DBA::update('post-thread-user', $update_fields, ['post-user-id' => $segment])) {
|
|
||||||
DBA::rollback();
|
DBA::rollback();
|
||||||
Logger::notice('Updating post-thread-user failed', ['fields' => $update_fields, 'condition' => $condition]);
|
Logger::notice('Updating post-thread-user failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$affected_count += DBA::affectedRows();
|
$affected_count += DBA::affectedRows();
|
||||||
}
|
}
|
||||||
|
DBA::close($posts);
|
||||||
$affected = max($affected, $affected_count);
|
$affected = max($affected, $affected_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue