Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
Implement paging for history.
Browse files Browse the repository at this point in the history
This is VITAL as otherwise opening history after any significant
amount of browsing can freeze your browser.

Learnt my lesson now, don't render lots of data into WebKit and
expect it to handle that. There's little reason anymore it should.
  • Loading branch information
Adrian Cochrane committed Mar 16, 2018
1 parent 6659e89 commit c18bbca
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
2 changes: 2 additions & 0 deletions data/pages/butterick.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ span[title] {
border-bottom: thin dotted gray;
cursor: help;
}

footer {text-align: center;}
8 changes: 7 additions & 1 deletion data/pages/debugging/test
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ and can be called at 212 555-1234.

{% endtest %}

{% test "{% for %} over a range" %}
{% for i in 4|add:2 %}{{i}}{% endfor %}
{% output %}
012345
{% endtest %}

{% test "{% if %}/{% else %} basics" %}
{% if nonempty %}y{% else %}n{% endif %}
{% if empty %}y{% else %}n{% endif %}
Expand Down Expand Up @@ -832,7 +838,7 @@ and can be called at 212 555-1234.
{% endtest %}

<h2>Filters</h2>
{% test "|add" %}{{ 4|add:2 }}{% output %}6{% endtest %}
{% test "|add" %}{{ 4|add:2 }} {{"4"|add:2}}{% output %}6 6{% endtest %}
{% test "|capfirst" %}{{ "oDDitY"|capfirst }}{% output %}ODDitY{% endtest %}
{% test "|cut" %}
{{"Stanly Kubrik's 2001: A Space Oddyssey"|cut:" "}}
Expand Down
26 changes: 21 additions & 5 deletions data/pages/history
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ and to visually communicate the paths surfers took through this history. #}
<title>[document-open-recent] {% trans %}History{% endtrans %}</title>
<style>@import url('odysseus:butterick.css');</style>
</head>
<body>
<body>{% with pagesize=400 %}
<h1>{% trans %}Browser History{% endtrans %}</h1>
<dl>{% query %}SELECT rowid, tab, uri, title, favicon, visited_at, referrer
FROM page_visit ORDER BY visited_at DESC;
FROM page_visit ORDER BY visited_at DESC
LIMIT {{ pagesize }} OFFSET {{ url.query.page|default:0 }}*{{ pagesize }};
{% each-row %}
{% with date=visited_at %}
{% ifchanged date|date:"%Y%B%e" %}<dt>
Expand All @@ -28,8 +29,23 @@ and to visually communicate the paths surfers took through this history. #}
<a href="{{ uri }}">{{title}}</a>
</dd>
{% empty %}
<dt>{% trans %}<strong>Wow</strong>! You've managed not to have any browser history! I'm impressed.{% endtrans %}</dt>
<dd>{% trans %}Please <a href="https://alcinnz.github.io/Odysseus-recommendations/">go explore</a>, then come back if you want.{% endtrans %}</dd>
<dt>{% trans %}Invalid page number!{% endtrans %}</dt>
{% endquery %}</dl>
<footer>
{% query %}SELECT count(*)/{{pagesize}} + 1 AS num_pages FROM page_visit;
{% each-row %}
{% for i in num_pages %}
{% if i != url.query.page %}<a href="odysseus:history?page={{i}}"{% else %}<strong {% endif %}
{% query %}SELECT min(visited_at) AS earliest, max(visited_at) AS latest FROM page_visit
LIMIT {{pagesize}} OFFSET {{i}}*{{pagesize}};
{% each-row %}
title="{{latest}} - {{earliest}}"
{% endquery %}
>●</{% if i != url.query.page %}a{% else %}span{% endif %}>
{% empty %}
{% trans %}Wow! No history. <a href="https://alcinnz.github.io/Odysseus-recommendations/">Go explore</a>!{% endtrans %}
{% endfor %}
{% endquery %}
</footer>
</body>
</html>
{% endwith %}</html>
9 changes: 9 additions & 0 deletions src/Services/Prosody/data.vala
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ namespace Odysseus.Templating.Data {
}

public override void foreach_map(Data.ForeachMap cb) {
if (data.holds(typeof(int)) || data.holds(typeof(double))) {
var to = to_int();
for (var i = 0; i < to; i++) if (cb(b(""), new Literal(i))) break;
return;
}
var text = to_string();

int index = 0;
Expand Down Expand Up @@ -148,12 +153,16 @@ namespace Odysseus.Templating.Data {

public override int to_int(out bool is_length = null) {
is_length = false;
if (data.holds(typeof(string))) return int.parse((string) data);

Value ret = Value(typeof(int));
if (data.transform(ref ret)) return ret.get_int();
else return 0;
}

public override double to_double() {
if (data.holds(typeof(string))) return double.parse((string) data);

Value ret = Value(typeof(double));
if (data.transform(ref ret)) return (double) ret;
else return 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Prosody/parser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ namespace Odysseus.Templating {

this.literal = new Data.Literal(ByteUtils.parse_string(base_text));
break;
case '0': case '1': case '2': case '3': case '4':
case '-': case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
double number;
if (!double.try_parse(ByteUtils.to_string(base_text), out number))
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Prosody/writers.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace Odysseus.Templating {

var builder = ArrayBuilder(buffer);
var bytes_read = 0;
while (bytes_read < buffer.length) {
while (bytes_read < int.min(1024, buffer.length)) {
// Ensures we have a buffer, and handle close_write() correctly.
while (data.length() == 0 && !closed) {
// Has to be lower than Priority.DEFAULT_IDLE
Expand Down
5 changes: 4 additions & 1 deletion src/Services/database/prosody.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ namespace Odysseus.Database.Prosody {
public DataSQLite(Sqlite.Value val) {this.val = val;}
public override Data.Data get(Bytes _) {return new Data.Empty();}
public override string to_string() {return val.to_text();}
public override void foreach_map(Data.Data.ForeachMap cb) {}
public override void foreach_map(Data.Data.ForeachMap cb) {
for (var i = 0; i < val.to_int(); i++)
if (cb(b(""), new Data.Literal(i))) break;
}
public override int to_int(out bool is_length = null) {
is_length = false;
// Implicitly add correct datetime parsing
Expand Down

0 comments on commit c18bbca

Please sign in to comment.