aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin J. Novack <jnovack@gmail.com>2012-09-30 17:43:58 -0400
committerJustin J. Novack <jnovack@gmail.com>2012-10-01 17:21:56 -0400
commitd5901a1fcc8b79f9a23bd3888ef2f281f07b9459 (patch)
treeb306fba401eadd70e3c042f6c0c935e08cc0c16c
parent8d29b8e073c9a3795ad7ededf4cb5e8683102162 (diff)
downloadphorkie-d5901a1fcc8b79f9a23bd3888ef2f281f07b9459.tar.gz
phorkie-d5901a1fcc8b79f9a23bd3888ef2f281f07b9459.zip
Use commit timestamps for ElasticSearch and sort on last commit time.
-rw-r--r--data/templates/list.htm11
-rw-r--r--data/templates/new.htm2
-rw-r--r--data/templates/repo-sidebar-list.htm2
-rw-r--r--scripts/index.php4
-rw-r--r--src/phorkie/Database/Adapter/Elasticsearch/Indexer.php37
-rw-r--r--src/phorkie/Database/Adapter/Elasticsearch/Search.php5
-rw-r--r--src/phorkie/Database/Adapter/Elasticsearch/Setup.php6
-rw-r--r--src/phorkie/Database/Adapter/Null/Indexer.php4
-rw-r--r--src/phorkie/Database/IIndexer.php4
-rw-r--r--src/phorkie/Database/ISearch.php3
-rw-r--r--www/list.php7
-rw-r--r--www/new.php2
12 files changed, 71 insertions, 16 deletions
diff --git a/data/templates/list.htm b/data/templates/list.htm
index d0732ea..aee3100 100644
--- a/data/templates/list.htm
+++ b/data/templates/list.htm
@@ -11,3 +11,14 @@
{% 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 %}
diff --git a/data/templates/new.htm b/data/templates/new.htm
index 7548c2a..0f69719 100644
--- a/data/templates/new.htm
+++ b/data/templates/new.htm
@@ -38,7 +38,7 @@ $(document).ready(function() {
{% block sidebar %}
{% if recents.results %}
- <h3>Recently created</h3>
+ <h3>Recently updated</h3>
<ul>
{% for repo in recents.repos %}
{% include 'repo-sidebar-list.htm' %}
diff --git a/data/templates/repo-sidebar-list.htm b/data/templates/repo-sidebar-list.htm
index ed262ac..cb9f3d8 100644
--- a/data/templates/repo-sidebar-list.htm
+++ b/data/templates/repo-sidebar-list.htm
@@ -2,5 +2,5 @@
<a href="{{repo.getLink('display')}}">
{{repo.getTitle}}
</a><br/>
- &#160;&#160;&#160;<span title="{{repo.crdate|date('c')}}">{{dh.get(repo.crdate)}}</span>
+ &#160;&#160;&#160;<span title="{{repo.modate|date('c')}}">{{dh.get(repo.modate)}}</span>
</li>
diff --git a/scripts/index.php b/scripts/index.php
index 4b529d1..5da912e 100644
--- a/scripts/index.php
+++ b/scripts/index.php
@@ -37,6 +37,8 @@ $rs = new Repositories();
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);
}
?>
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php
index cf50bbe..e93cfa7 100644
--- a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php
+++ b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php
@@ -9,15 +9,18 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
}
- 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(
@@ -35,6 +38,12 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
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();
@@ -83,6 +92,28 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
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(
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Search.php b/src/phorkie/Database/Adapter/Elasticsearch/Search.php
index e960e04..ddbc13b 100644
--- a/src/phorkie/Database/Adapter/Elasticsearch/Search.php
+++ b/src/phorkie/Database/Adapter/Elasticsearch/Search.php
@@ -6,6 +6,7 @@ class Database_Adapter_Elasticsearch_Search implements Database_ISearch
protected static $sortMap = array(
'id' => array('id', 'asc'),
'crdate' => array('crdate', 'desc'),
+ 'modate' => array('modate', 'desc'),
'tstamp' => array('tstamp', 'desc'),
);
@@ -22,7 +23,8 @@ class Database_Adapter_Elasticsearch_Search implements Database_ISearch
* @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
*/
@@ -64,6 +66,7 @@ class Database_Adapter_Elasticsearch_Search implements Database_ISearch
$r = new Repository();
$r->loadById($hit->_source->id);
$r->crdate = strtotime($hit->_source->crdate);
+ $r->modate = strtotime($hit->_source->modate);
$sres->repos[] = $r;
}
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Setup.php b/src/phorkie/Database/Adapter/Elasticsearch/Setup.php
index 0df2874..bb76d54 100644
--- a/src/phorkie/Database/Adapter/Elasticsearch/Setup.php
+++ b/src/phorkie/Database/Adapter/Elasticsearch/Setup.php
@@ -59,9 +59,13 @@ class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
//creation date
'type' => 'date',
),
- 'tstamp' => (object)array(
+ 'modate' => (object)array(
//modification date
'type' => 'date',
+ ),
+ 'tstamp' => (object)array(
+ //last indexed date
+ 'type' => 'date',
)
)
)
diff --git a/src/phorkie/Database/Adapter/Null/Indexer.php b/src/phorkie/Database/Adapter/Null/Indexer.php
index 3b0c990..4ad63f1 100644
--- a/src/phorkie/Database/Adapter/Null/Indexer.php
+++ b/src/phorkie/Database/Adapter/Null/Indexer.php
@@ -3,11 +3,11 @@ namespace phorkie;
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)
{
}
diff --git a/src/phorkie/Database/IIndexer.php b/src/phorkie/Database/IIndexer.php
index 61b8a87..232e1ee 100644
--- a/src/phorkie/Database/IIndexer.php
+++ b/src/phorkie/Database/IIndexer.php
@@ -3,8 +3,8 @@ namespace phorkie;
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);
}
diff --git a/src/phorkie/Database/ISearch.php b/src/phorkie/Database/ISearch.php
index c33867b..f67dec6 100644
--- a/src/phorkie/Database/ISearch.php
+++ b/src/phorkie/Database/ISearch.php
@@ -13,7 +13,8 @@ interface Database_ISearch
* @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
*/
diff --git a/www/list.php b/www/list.php
index 750e811..d4934bd 100644
--- a/www/list.php
+++ b/www/list.php
@@ -22,11 +22,14 @@ $pager = new Html_Pager(
$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(),
)
);
?>
diff --git a/www/new.php b/www/new.php
index 7a70891..965f534 100644
--- a/www/new.php
+++ b/www/new.php
@@ -28,7 +28,7 @@ render(
'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(),
)
);