2011-07-12 00:06:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-10 00:46:25 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-07-12 00:06:19 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-09-14 17:02:31 +02:00
|
|
|
/**
|
|
|
|
* @group phriction
|
|
|
|
*/
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhrictionHistoryController
|
2011-07-12 00:06:19 +02:00
|
|
|
extends PhrictionController {
|
|
|
|
|
|
|
|
private $slug;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->slug = $data['slug'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$document = id(new PhrictionDocument())->loadOneWhere(
|
|
|
|
'slug = %s',
|
2012-04-10 23:18:20 +02:00
|
|
|
PhabricatorSlug::normalize($this->slug));
|
2011-07-12 00:06:19 +02:00
|
|
|
|
|
|
|
if (!$document) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2011-07-17 20:06:02 +02:00
|
|
|
$current = id(new PhrictionContent())->load($document->getContentID());
|
|
|
|
|
2011-07-12 00:06:19 +02:00
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setOffset($request->getInt('page'));
|
|
|
|
$pager->setURI($request->getRequestURI(), 'page');
|
|
|
|
|
|
|
|
$history = id(new PhrictionContent())->loadAllWhere(
|
|
|
|
'documentID = %d ORDER BY version DESC LIMIT %d, %d',
|
|
|
|
$document->getID(),
|
|
|
|
$pager->getOffset(),
|
|
|
|
$pager->getPageSize() + 1);
|
|
|
|
$history = $pager->sliceResults($history);
|
|
|
|
|
|
|
|
$author_phids = mpull($history, 'getAuthorPHID');
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($author_phids))
|
|
|
|
->loadHandles();
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($history as $content) {
|
|
|
|
|
Add a generic multistep Markup cache
Summary:
The immediate issue this addresses is T1366, adding a rendering cache to Phriction. For wiki pages with code blocks especially, rerendering them each time is expensive.
The broader issue is that out markup caches aren't very good right now. They have three major problems:
**Problem 1: the data is stored in the wrong place.** We currently store remarkup caches on objects. This means we're always loading it and passing it around even when we don't need it, can't genericize cache management code (e.g., have one simple script to drop/GC caches), need to update authoritative rows to clear caches, and can't genericize rendering code since each object is different.
To solve this, I created a dedicated cache database that I plan to move all markup caches to use.
**Problem 2: time-variant rules break when cached.** Some rules like `**bold**` are time-invariant and always produce the same output, but some rules like `{Tnnn}` and `@username` are variant and may render differently (because a task was closed or a user is on vacation). Currently, we cache the raw output, so these time-variant rules get locked at whatever values they had when they were first rendered. This is the main reason Phriction doesn't have a cache right now -- I wanted `{Tnnn}` rules to reflect open/closed tasks.
To solve this, I split markup into a "preprocessing" phase (which does all the parsing and evaluates all time-invariant rules) and a "postprocessing" phase (which evaluates time-variant rules only). The preprocessing phase is most of the expense (and, notably, includes syntax highlighting) so this is nearly as good as caching the final output. I did most of the work here in D737 / D738, but we never moved to use it in Phabricator -- we currently just do the two operations serially in all cases.
This diff splits them apart and caches the output of preprocessing only, so we benefit from caching but also get accurate time-variant rendering.
**Problem 3: cache access isn't batched/pipelined optimally.** When we're rendering a list of markup blocks, we should be able to batch datafetching better than we do. D738 helped with this (fetching is batched within a single hunk of markup) and this improves batching on cache access. We could still do better here, but this is at least a step forward.
Also fixes a bug with generating a link in the Phriction history interface ($uri gets clobbered).
I'm using PHP serialization instead of JSON serialization because Remarkup does some stuff with non-ascii characters that might not survive JSON.
Test Plan:
- Created a Phriction document and verified that previews don't go to cache (no rows appear in the cache table).
- Verified that published documents come out of cache.
- Verified that caches generate/regenerate correctly, time-variant rules render properly and old documents hit the right caches.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1366
Differential Revision: https://secure.phabricator.com/D2945
2012-07-10 00:20:56 +02:00
|
|
|
$slug_uri = PhrictionDocument::getSlugURI($document->getSlug());
|
2011-07-13 03:03:20 +02:00
|
|
|
$version = $content->getVersion();
|
2011-07-12 00:06:19 +02:00
|
|
|
|
2011-07-17 20:06:02 +02:00
|
|
|
$diff_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/');
|
|
|
|
|
|
|
|
$vs_previous = '<em>Created</em>';
|
|
|
|
if ($content->getVersion() != 1) {
|
|
|
|
$uri = $diff_uri
|
|
|
|
->alter('l', $content->getVersion() - 1)
|
|
|
|
->alter('r', $content->getVersion());
|
|
|
|
$vs_previous = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $uri,
|
|
|
|
),
|
|
|
|
'Show Change');
|
|
|
|
}
|
|
|
|
|
|
|
|
$vs_head = '<em>Current</em>';
|
|
|
|
if ($content->getID() != $document->getContentID()) {
|
|
|
|
$uri = $diff_uri
|
|
|
|
->alter('l', $content->getVersion())
|
|
|
|
->alter('r', $current->getVersion());
|
|
|
|
|
|
|
|
$vs_head = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $uri,
|
|
|
|
),
|
|
|
|
'Show Later Changes');
|
|
|
|
}
|
|
|
|
|
2011-12-17 18:19:08 +01:00
|
|
|
$change_type = PhrictionChangeType::getChangeTypeLabel(
|
|
|
|
$content->getChangeType());
|
|
|
|
|
2011-07-12 00:06:19 +02:00
|
|
|
$rows[] = array(
|
|
|
|
phabricator_date($content->getDateCreated(), $user),
|
|
|
|
phabricator_time($content->getDateCreated(), $user),
|
2011-07-13 03:03:20 +02:00
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
Add a generic multistep Markup cache
Summary:
The immediate issue this addresses is T1366, adding a rendering cache to Phriction. For wiki pages with code blocks especially, rerendering them each time is expensive.
The broader issue is that out markup caches aren't very good right now. They have three major problems:
**Problem 1: the data is stored in the wrong place.** We currently store remarkup caches on objects. This means we're always loading it and passing it around even when we don't need it, can't genericize cache management code (e.g., have one simple script to drop/GC caches), need to update authoritative rows to clear caches, and can't genericize rendering code since each object is different.
To solve this, I created a dedicated cache database that I plan to move all markup caches to use.
**Problem 2: time-variant rules break when cached.** Some rules like `**bold**` are time-invariant and always produce the same output, but some rules like `{Tnnn}` and `@username` are variant and may render differently (because a task was closed or a user is on vacation). Currently, we cache the raw output, so these time-variant rules get locked at whatever values they had when they were first rendered. This is the main reason Phriction doesn't have a cache right now -- I wanted `{Tnnn}` rules to reflect open/closed tasks.
To solve this, I split markup into a "preprocessing" phase (which does all the parsing and evaluates all time-invariant rules) and a "postprocessing" phase (which evaluates time-variant rules only). The preprocessing phase is most of the expense (and, notably, includes syntax highlighting) so this is nearly as good as caching the final output. I did most of the work here in D737 / D738, but we never moved to use it in Phabricator -- we currently just do the two operations serially in all cases.
This diff splits them apart and caches the output of preprocessing only, so we benefit from caching but also get accurate time-variant rendering.
**Problem 3: cache access isn't batched/pipelined optimally.** When we're rendering a list of markup blocks, we should be able to batch datafetching better than we do. D738 helped with this (fetching is batched within a single hunk of markup) and this improves batching on cache access. We could still do better here, but this is at least a step forward.
Also fixes a bug with generating a link in the Phriction history interface ($uri gets clobbered).
I'm using PHP serialization instead of JSON serialization because Remarkup does some stuff with non-ascii characters that might not survive JSON.
Test Plan:
- Created a Phriction document and verified that previews don't go to cache (no rows appear in the cache table).
- Verified that published documents come out of cache.
- Verified that caches generate/regenerate correctly, time-variant rules render properly and old documents hit the right caches.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T1366
Differential Revision: https://secure.phabricator.com/D2945
2012-07-10 00:20:56 +02:00
|
|
|
'href' => $slug_uri.'?v='.$version,
|
2011-07-13 03:03:20 +02:00
|
|
|
),
|
|
|
|
'Version '.$version),
|
2011-07-12 00:06:19 +02:00
|
|
|
$handles[$content->getAuthorPHID()]->renderLink(),
|
2011-12-17 18:19:08 +01:00
|
|
|
$change_type,
|
2011-07-22 00:32:54 +02:00
|
|
|
phutil_escape_html($content->getDescription()),
|
2011-07-17 20:06:02 +02:00
|
|
|
$vs_previous,
|
|
|
|
$vs_head,
|
2011-07-12 00:06:19 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-12-15 21:00:17 +01:00
|
|
|
$crumbs = new AphrontCrumbsView();
|
|
|
|
$crumbs->setCrumbs(
|
|
|
|
array(
|
|
|
|
'Phriction',
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => PhrictionDocument::getSlugURI($document->getSlug()),
|
|
|
|
),
|
|
|
|
phutil_escape_html($current->getTitle())
|
|
|
|
),
|
|
|
|
'History',
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2011-07-12 00:06:19 +02:00
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Date',
|
|
|
|
'Time',
|
|
|
|
'Version',
|
|
|
|
'Author',
|
2011-12-17 18:19:08 +01:00
|
|
|
'Type',
|
2011-07-17 20:06:02 +02:00
|
|
|
'Description',
|
|
|
|
'Against Previous',
|
|
|
|
'Against Current',
|
2011-07-12 00:06:19 +02:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'right',
|
2011-07-17 20:06:02 +02:00
|
|
|
'pri',
|
2011-07-12 00:06:19 +02:00
|
|
|
'',
|
2011-12-17 18:19:08 +01:00
|
|
|
'',
|
2011-07-12 00:06:19 +02:00
|
|
|
'wide',
|
2011-07-17 20:06:02 +02:00
|
|
|
'',
|
|
|
|
'',
|
2011-07-12 00:06:19 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Document History');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
$panel->appendChild($pager);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
2011-12-15 21:00:17 +01:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$panel,
|
|
|
|
),
|
2011-07-12 00:06:19 +02:00
|
|
|
array(
|
|
|
|
'title' => 'Document History',
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|