{% include 'pager.htm' %}
{% endblock %}
+
+{% block sidebar %}
+ {% if recents.results %}
+ <h3>Recently updated</h3>
+ <ul>
+ {% for repo in recents.repos %}
+ {% include 'repo-sidebar-list.htm' %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+{% endblock %}
{% block sidebar %}
{% if recents.results %}
- <h3>Recently created</h3>
+ <h3>Recently updated</h3>
<ul>
{% for repo in recents.repos %}
{% include 'repo-sidebar-list.htm' %}
<a href="{{repo.getLink('display')}}">
{{repo.getTitle}}
</a><br/>
-    <span title="{{repo.crdate|date('c')}}">{{dh.get(repo.crdate)}}</span>
+    <span title="{{repo.modate|date('c')}}">{{dh.get(repo.modate)}}</span>
</li>
list($repos, $count) = $rs->getList(0, 10000);
foreach ($repos as $repo) {
echo 'Indexing ' . $repo->id . "\n";
- $idx->addRepo($repo, filectime($repo->gitDir));
+ $commits = $repo->getHistory();
+ $first = count($commits)-1;
+ $idx->addRepo($repo, $commits[$first]->committerTime, $commits[0]->committerTime);
}
?>
}
- public function addRepo(Repository $repo, $crdate = null)
+ public function addRepo(Repository $repo, $crdate = null, $modate = null)
{
if ($crdate == null) {
$crdate = time();
}
- $this->updateRepo($repo, $crdate);
+ if ($modate == null) {
+ $modate = time();
+ }
+ $this->updateRepo($repo, $crdate, $modate);
}
- public function updateRepo(Repository $repo, $crdate = null)
+ public function updateRepo(Repository $repo, $crdate = null, $modate = null)
{
//add repository
$r = new Database_Adapter_Elasticsearch_HTTPRequest(
if ($crdate !== null) {
$repoData['crdate'] = gmdate('c', $crdate);
}
+ if ($modate == null) {
+ $modate = $this->getMoDate($repo);
+ }
+ if ($modate !== null) {
+ $repoData['modate'] = gmdate('c', $modate);
+ }
$r->setBody(json_encode((object)$repoData));
$r->send();
return strtotime($json->_source->crdate);
}
+ /**
+ * When updating the repository, we don't have a modification date.
+ * We need to keep it, but elasticsearch does not have a simple way
+ * to update some fields only (without using a custom script).
+ *
+ * @return integer Unix timestamp
+ */
+ protected function getMoDate(Repository $repo)
+ {
+ $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+ $this->searchInstance . 'repo/' . $repo->id,
+ \HTTP_Request2::METHOD_GET
+ );
+ $json = json_decode($r->send()->getBody());
+
+ if (!isset($json->_source->modate)) {
+ return null;
+ }
+
+ return strtotime($json->_source->modate);
+ }
+
public function deleteAllRepos()
{
$r = new Database_Adapter_Elasticsearch_HTTPRequest(
protected static $sortMap = array(
'id' => array('id', 'asc'),
'crdate' => array('crdate', 'desc'),
+ 'modate' => array('modate', 'desc'),
'tstamp' => array('tstamp', 'desc'),
);
* @param string $sort Sort order. Allowed values:
* - id - repository id
* - crdate - creation date
- * - tstamp - modification date
+ * - modate - modification date
+ * - tstamp - last index date
*
* @return Search_Result Search result object
*/
$r = new Repository();
$r->loadById($hit->_source->id);
$r->crdate = strtotime($hit->_source->crdate);
+ $r->modate = strtotime($hit->_source->modate);
$sres->repos[] = $r;
}
//creation date
'type' => 'date',
),
- 'tstamp' => (object)array(
+ 'modate' => (object)array(
//modification date
'type' => 'date',
+ ),
+ 'tstamp' => (object)array(
+ //last indexed date
+ 'type' => 'date',
)
)
)
class Database_Adapter_Null_Indexer
{
- public function addRepo(Repository $repo, $crdate = null)
+ public function addRepo(Repository $repo, $crdate = null, $modate = null)
{
}
- public function updateRepo(Repository $repo, $crdate = null)
+ public function updateRepo(Repository $repo, $crdate = null, $modate = null)
{
}
interface Database_IIndexer
{
- public function addRepo(Repository $repo, $crdate = null);
- public function updateRepo(Repository $repo, $crdate = null);
+ public function addRepo(Repository $repo, $crdate = null, $modate = null);
+ public function updateRepo(Repository $repo, $crdate = null, $modate = null);
public function deleteAllRepos();
public function deleteRepo(Repository $repo);
}
* @param string $sort Sort order. Allowed values:
* - id - repository id
* - crdate - creation date
- * - tstamp - modification date
+ * - modate - modification date
+ * - tstamp - last index date
*
* @return Search_Result Search result object
*/
$repoCount, $perPage, $page + 1, '/list/%d'
);
+$db = new Database();
render(
'list',
array(
- 'repos' => $repos,
- 'pager' => $pager,
+ 'repos' => $repos,
+ 'pager' => $pager,
+ 'recents' => $db->getSearch()->listAll(0, 5, 'modate', 'desc'),
+ 'dh' => new \Date_HumanDiff(),
)
);
?>
'files' => $phork,
'description' => '',
'htmlhelper' => new HtmlHelper(),
- 'recents' => $db->getSearch()->listAll(0, 5, 'crdate', 'desc'),
+ 'recents' => $db->getSearch()->listAll(0, 5, 'modate', 'desc'),
'dh' => new \Date_HumanDiff(),
)
);