mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40:55 +01:00
Don't store empty drafts
Summary: We have lots of empty drafts in DB. Test Plan: Wrote revision comment, deleted it, checked db. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3591
This commit is contained in:
parent
6b9b1d4f95
commit
3d6a3e28fa
5 changed files with 35 additions and 30 deletions
|
@ -75,7 +75,7 @@ final class PhabricatorAuditPreviewController
|
|||
->setAuthorPHID($comment->getActorPHID())
|
||||
->setDraftKey('diffusion-audit-'.$this->id)
|
||||
->setDraft($comment->getContent())
|
||||
->replace();
|
||||
->replaceOrDelete();
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($view->render());
|
||||
|
|
|
@ -66,17 +66,20 @@ final class DifferentialCommentPreviewController
|
|||
$view->setPreview(true);
|
||||
$view->setTargetDiff(null);
|
||||
|
||||
$draft = new PhabricatorDraft();
|
||||
$draft
|
||||
$metadata = array(
|
||||
'reviewers' => $reviewers,
|
||||
'ccs' => $ccs,
|
||||
);
|
||||
if ($action != DifferentialAction::ACTION_COMMENT) {
|
||||
$metadata['action'] = $action;
|
||||
}
|
||||
|
||||
id(new PhabricatorDraft())
|
||||
->setAuthorPHID($author_phid)
|
||||
->setDraftKey('differential-comment-'.$this->id)
|
||||
->setDraft($comment->getContent())
|
||||
->setMetadata(array(
|
||||
'action' => $action,
|
||||
'reviewers' => $reviewers,
|
||||
'ccs' => $ccs,
|
||||
))
|
||||
->replace();
|
||||
->setMetadata($metadata)
|
||||
->replaceOrDelete();
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($view->render());
|
||||
|
|
|
@ -31,4 +31,17 @@ final class PhabricatorDraft extends PhabricatorDraftDAO {
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function replaceOrDelete() {
|
||||
if ($this->draft == '' && !array_filter($this->metadata)) {
|
||||
queryfx(
|
||||
$this->establishConnection('w'),
|
||||
'DELETE FROM %T WHERE authorPHID = %s AND draftKey = %s',
|
||||
$this->getTableName(),
|
||||
$this->authorPHID,
|
||||
$this->draftKey);
|
||||
return $this;
|
||||
}
|
||||
return parent::replace();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,18 +39,11 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
|
|||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$draft = id(new PhabricatorDraft())->loadOneWhere(
|
||||
'authorPHID = %s AND draftKey = %s',
|
||||
$user->getPHID(),
|
||||
$task->getPHID());
|
||||
if (!$draft) {
|
||||
$draft = new PhabricatorDraft();
|
||||
$draft->setAuthorPHID($user->getPHID());
|
||||
$draft->setDraftKey($task->getPHID());
|
||||
}
|
||||
$draft->setDraft($comments);
|
||||
$draft->save();
|
||||
|
||||
id(new PhabricatorDraft())
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setDraftKey($task->getPHID())
|
||||
->setDraft($comments)
|
||||
->replaceOrDelete();
|
||||
|
||||
$action = $request->getStr('action');
|
||||
|
||||
|
|
|
@ -29,15 +29,11 @@ final class PhrictionDocumentPreviewController
|
|||
|
||||
$draft_key = $request->getStr('draftkey');
|
||||
if ($draft_key) {
|
||||
$table = new PhabricatorDraft();
|
||||
queryfx(
|
||||
$table->establishConnection('w'),
|
||||
'INSERT INTO %T (authorPHID, draftKey, draft) VALUES (%s, %s, %s)
|
||||
ON DUPLICATE KEY UPDATE draft = VALUES(draft)',
|
||||
$table->getTableName(),
|
||||
$request->getUser()->getPHID(),
|
||||
$draft_key,
|
||||
$document);
|
||||
id(new PhabricatorDraft())
|
||||
->setAuthorPHID($request->getUser()->getPHID())
|
||||
->setDraftKey($draft_key)
|
||||
->setDraft($document)
|
||||
->replaceOrDelete();
|
||||
}
|
||||
|
||||
$content_obj = new PhrictionContent();
|
||||
|
|
Loading…
Reference in a new issue