1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50: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:
vrana 2012-10-01 15:50:47 -07:00
parent 6b9b1d4f95
commit 3d6a3e28fa
5 changed files with 35 additions and 30 deletions

View file

@ -75,7 +75,7 @@ final class PhabricatorAuditPreviewController
->setAuthorPHID($comment->getActorPHID()) ->setAuthorPHID($comment->getActorPHID())
->setDraftKey('diffusion-audit-'.$this->id) ->setDraftKey('diffusion-audit-'.$this->id)
->setDraft($comment->getContent()) ->setDraft($comment->getContent())
->replace(); ->replaceOrDelete();
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent($view->render()); ->setContent($view->render());

View file

@ -66,17 +66,20 @@ final class DifferentialCommentPreviewController
$view->setPreview(true); $view->setPreview(true);
$view->setTargetDiff(null); $view->setTargetDiff(null);
$draft = new PhabricatorDraft(); $metadata = array(
$draft 'reviewers' => $reviewers,
'ccs' => $ccs,
);
if ($action != DifferentialAction::ACTION_COMMENT) {
$metadata['action'] = $action;
}
id(new PhabricatorDraft())
->setAuthorPHID($author_phid) ->setAuthorPHID($author_phid)
->setDraftKey('differential-comment-'.$this->id) ->setDraftKey('differential-comment-'.$this->id)
->setDraft($comment->getContent()) ->setDraft($comment->getContent())
->setMetadata(array( ->setMetadata($metadata)
'action' => $action, ->replaceOrDelete();
'reviewers' => $reviewers,
'ccs' => $ccs,
))
->replace();
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent($view->render()); ->setContent($view->render());

View file

@ -31,4 +31,17 @@ final class PhabricatorDraft extends PhabricatorDraftDAO {
) + parent::getConfiguration(); ) + 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();
}
} }

View file

@ -39,18 +39,11 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
return new Aphront404Response(); return new Aphront404Response();
} }
$draft = id(new PhabricatorDraft())->loadOneWhere( id(new PhabricatorDraft())
'authorPHID = %s AND draftKey = %s', ->setAuthorPHID($user->getPHID())
$user->getPHID(), ->setDraftKey($task->getPHID())
$task->getPHID()); ->setDraft($comments)
if (!$draft) { ->replaceOrDelete();
$draft = new PhabricatorDraft();
$draft->setAuthorPHID($user->getPHID());
$draft->setDraftKey($task->getPHID());
}
$draft->setDraft($comments);
$draft->save();
$action = $request->getStr('action'); $action = $request->getStr('action');

View file

@ -29,15 +29,11 @@ final class PhrictionDocumentPreviewController
$draft_key = $request->getStr('draftkey'); $draft_key = $request->getStr('draftkey');
if ($draft_key) { if ($draft_key) {
$table = new PhabricatorDraft(); id(new PhabricatorDraft())
queryfx( ->setAuthorPHID($request->getUser()->getPHID())
$table->establishConnection('w'), ->setDraftKey($draft_key)
'INSERT INTO %T (authorPHID, draftKey, draft) VALUES (%s, %s, %s) ->setDraft($document)
ON DUPLICATE KEY UPDATE draft = VALUES(draft)', ->replaceOrDelete();
$table->getTableName(),
$request->getUser()->getPHID(),
$draft_key,
$document);
} }
$content_obj = new PhrictionContent(); $content_obj = new PhrictionContent();