Skip to content

Commit

Permalink
improved views and added duplicates to index
Browse files Browse the repository at this point in the history
  • Loading branch information
mattetti committed Jul 25, 2009
1 parent 777ea73 commit 2958e1e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
15 changes: 14 additions & 1 deletion lib/templates/index/head.html
Expand Up @@ -13,4 +13,17 @@
<h2><%= title %></h2>
</div>
<div class="container">
<ul>
<table id="requests">
<thead>
<tr>
<th class='span-2'>Date</th>
<th class='span-11'>URL</th>
<th class='span-1'>Duration</th>
<th class='span-3'>Queries</th>
<th class='span-3'>Duplicates</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- row partial -->
<!-- tail partial -->
24 changes: 8 additions & 16 deletions lib/templates/index/row.html
@@ -1,16 +1,8 @@
<li>
<div class='container'>
<div class="span-24 last">
<span class='req-url'><%= url %></span> (<span class='date'><%= timestamp %></span>)
</div>
<div class="span-4">
Duration: <span class='duration'><%= duration %></span>s
</div>
<div class="span-16">
queries: <%= amount_queries %>
</div>
<div class="span-4 last">
<a href="<%= link %>">More Info</a>
</div>
</div>
</li>
<tr>
<td><span class='date'><%= timestamp %></span></td>
<td><span class='req-url'><%= url %></span></td>
<td><span class='duration'><%= duration %></span>s</td>
<td><%= amount_queries %> DB queries</td>
<td><%= duplicates %> duplicates</td>
<td><a href="<%= link %>">More Info</a></td>
</tr>
12 changes: 8 additions & 4 deletions lib/templates/index/tail.html
@@ -1,19 +1,23 @@
</ul>
</tbody>
</table>
</div>
</div>
</body>
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
<script src="../../vendor/couchapp/jquery.couchapp.js"></script>
<script src="../../vendor/couchapp/jquery.couchapp.js"></script>
<script type="text/javascript" language="javascript" src="./../../javascripts/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
$.CouchApp(function(app) {
$('.date').each(function() {
$(this).text(app.prettyDate(this.innerHTML));
});
$('.duration').each(function(){
var duration = parseFloat($(this).text());
$(this).text(Math.round(duration*1000)/1000 + " s");
})
$(this).text(Math.round(duration*1000)/1000);
})
$('#requests').dataTable({iDisplayLength : 25});

});
</script>
Expand Down
2 changes: 0 additions & 2 deletions lib/templates/log/tail.html
Expand Up @@ -7,8 +7,6 @@
<script src="/_utils/script/jquery.couch.js"></script>
<script src="../../vendor/couchapp/jquery.couchapp.js"></script>
<script type="text/javascript" language="javascript" src="./../../javascripts/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf-8">
</script>
<script type="text/javascript" charset="utf-8">
$.CouchApp(function(app) {
$('.date').each(function() {
Expand Down
4 changes: 3 additions & 1 deletion lists/index.js
Expand Up @@ -5,19 +5,21 @@ function(head, row, req, info) {
// !code vendor/couchapp/date.js
// !code vendor/couchapp/template.js

var indexPath = listPath('index','recent-logs',{descending:true, limit:5});
var indexPath = listPath('index','recent-logs',{descending:true, limit:50});
// var feedPath = listPath('index','recent-logs',{descending:true, limit:5, format:"atom"});
return respondWith(req, {
html : function() {
if (head) {
return template(lib.templates.index.head, {title : 'Latest logs'})
} else if (row) {
var log = row.value;

return template(lib.templates.index.row, {
timestamp : log.timestamp,
url : log.url,
duration : log.duration,
amount_queries : log.amount_queries,
duplicates : log.amount_duplicates,
link : showPath('log', row.id),
});
} else {
Expand Down
23 changes: 17 additions & 6 deletions views/recent-logs/map.js
@@ -1,8 +1,19 @@
function(doc) {
emit(doc.started_at, {
timestamp : doc.started_at,
duration : doc.duration,
url : doc.url,
amount_queries : (doc['queries'] ? doc.queries.length : 0 )
});
var duplicates = [];
if(doc['queries']){
var flattened_queries = doc.queries.map(function(query){ return (query['method'] + query['url'] + ((query['payload'] && query['payload']['keys']) ? query.payload.keys.join(', ') : '') ) }).sort();
for (var i = 0; i < flattened_queries.length - 1; i += 1) {
if (flattened_queries[i + 1] == flattened_queries[i]) {
duplicates.push(flattened_queries[i]);
};
};
};

emit(doc.started_at, {
timestamp : doc.started_at,
duration : doc.duration,
url : doc.url,
amount_queries : (doc['queries'] ? doc.queries.length : 0 ),
amount_duplicates : duplicates.length
});
};

0 comments on commit 2958e1e

Please sign in to comment.