Skip to content
Browse files

Display in-memory data as soon as available

  • Loading branch information...
1 parent 511bdda commit 33d733c7c3d04c61cb73bc2972b04ee06f831e03 @swaroopch committed
Showing with 15 additions and 11 deletions.
  1. +8 −6 resources/book.mustache
  2. +7 −5 src/isbnnetinclj2/store.clj
View
14 resources/book.mustache
@@ -36,14 +36,14 @@
{{/binding}}
{{/info}}
</dl>
- {{^price}}
+ {{^pricePresent}}
<p><em>Fetching info and prices... page will refresh automatically.</em></p>
<script type="text/javascript">
window.onload = function() {
setTimeout("window.location.reload(true)", 20 * 1000);
};
</script>
- {{/price}}
+ {{/pricePresent}}
</div>
<div class="span4">
{{#info}}
@@ -67,12 +67,13 @@
</div>
</div>
-{{#price}}
+{{#pricePresent}}
<div class="container-fluid">
<div class="row-fluid">
<div class="span4 offset2">
<h3>Prices</h3>
<table class="table table-bordered table-hover">
+ {{#price}}
<tr>
{{#url}}
<th><a href="{{url}}">{{name}}</a></th>
@@ -80,12 +81,13 @@
{{^url}}
<th>{{name}}</th>
{{/url}}
- <td>{{amount}}</td>
- </tr>
+ <td>{{amount}}</td>
+ </tr>
+ {{/price}}
</table>
</div>
</div>
</div>
-{{/price}}
+{{/pricePresent}}
{{>footer}}
View
12 src/isbnnetinclj2/store.clj
@@ -271,10 +271,11 @@
(defn book-data
[isbn]
- (or (mongo/get-recent-entry isbn)
- (do
- (future (fetch-all-stores isbn))
- {:when (time/now)})))
+ (or (get @book-data-cache isbn)
+ (or (mongo/get-recent-entry isbn)
+ (do
+ (future (fetch-all-stores isbn))
+ {:when (time/now)}))))
(defn book-page
@@ -294,7 +295,8 @@
"book"
(merge
data
- {:isbn isbn
+ {:pricePresent (> (count price) 0)
+ :isbn isbn
:pageTitle (or (get-in data [:info :title])
isbn)
:price price}))))

0 comments on commit 33d733c

Please sign in to comment.
Something went wrong with that request. Please try again.