Load new history items from next item's time.
This commit is contained in:
parent
c4416c8ac0
commit
783769d302
@ -179,8 +179,17 @@ def qute_history(url):
|
|||||||
|
|
||||||
end_time = start_time - 24*60*60 # end is 24hrs earlier than start
|
end_time = start_time - 24*60*60 # end is 24hrs earlier than start
|
||||||
|
|
||||||
|
# when history_dict is not reversed, we need to keep track of last item
|
||||||
|
# so that we can yield its atime
|
||||||
|
last_item = None
|
||||||
|
|
||||||
for item in history:
|
for item in history:
|
||||||
# Abort/continue as early as possible
|
# Skip redirects
|
||||||
|
# Skip qute:// links
|
||||||
|
if item.redirect or item.url.scheme() == 'qute':
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Skip items out of time window
|
||||||
item_newer = item.atime > start_time
|
item_newer = item.atime > start_time
|
||||||
item_older = item.atime <= end_time
|
item_older = item.atime <= end_time
|
||||||
if reverse:
|
if reverse:
|
||||||
@ -189,6 +198,7 @@ def qute_history(url):
|
|||||||
# abort if item is older than start_time+24hr
|
# abort if item is older than start_time+24hr
|
||||||
# skip if item is newer than start
|
# skip if item is newer than start
|
||||||
if item_older:
|
if item_older:
|
||||||
|
yield {"next": int(item.atime)}
|
||||||
return
|
return
|
||||||
if item_newer:
|
if item_newer:
|
||||||
continue
|
continue
|
||||||
@ -198,15 +208,12 @@ def qute_history(url):
|
|||||||
# abort if item is newer than start_time
|
# abort if item is newer than start_time
|
||||||
# skip if item is older than start_time+24hrs
|
# skip if item is older than start_time+24hrs
|
||||||
if item_older:
|
if item_older:
|
||||||
|
last_item = item
|
||||||
continue
|
continue
|
||||||
if item_newer:
|
if item_newer:
|
||||||
|
yield {"next": int(last_item.atime)}
|
||||||
return
|
return
|
||||||
|
|
||||||
# Skip redirects
|
|
||||||
# Skip qute:// links
|
|
||||||
if item.redirect or item.url.scheme() == 'qute':
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Use item's url as title if there's no title.
|
# Use item's url as title if there's no title.
|
||||||
item_url = item.url.toDisplayString()
|
item_url = item.url.toDisplayString()
|
||||||
item_title = item.title if item.title else item_url
|
item_title = item.title if item.title else item_url
|
||||||
@ -214,6 +221,9 @@ def qute_history(url):
|
|||||||
|
|
||||||
yield {"url": item_url, "title": item_title, "time": item_time}
|
yield {"url": item_url, "title": item_title, "time": item_time}
|
||||||
|
|
||||||
|
# if we reached here, we had reached the end of history
|
||||||
|
yield {"next": -1}
|
||||||
|
|
||||||
if url.path() == '/data':
|
if url.path() == '/data':
|
||||||
# Use start_time in query or current time.
|
# Use start_time in query or current time.
|
||||||
try:
|
try:
|
||||||
|
@ -28,6 +28,19 @@ table {
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#load {
|
||||||
|
color: #555;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#eof {
|
||||||
|
color: #aaa;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.session-separator {
|
.session-separator {
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
@ -43,6 +56,8 @@ table {
|
|||||||
var global = {
|
var global = {
|
||||||
// The last history item that was seen.
|
// The last history item that was seen.
|
||||||
lastItem: null,
|
lastItem: null,
|
||||||
|
// The next time to load
|
||||||
|
nextTime: null,
|
||||||
// The cutoff interval for session-separator (30 minutes)
|
// The cutoff interval for session-separator (30 minutes)
|
||||||
SESSION_CUTOFF: 30*60
|
SESSION_CUTOFF: 30*60
|
||||||
};
|
};
|
||||||
@ -144,14 +159,25 @@ var getJSON = function(url, callback) {
|
|||||||
*/
|
*/
|
||||||
var loadHistory = function() {
|
var loadHistory = function() {
|
||||||
url = "qute://history/data";
|
url = "qute://history/data";
|
||||||
if (global.lastItem !== null) {
|
if (global.nextTime !== null) {
|
||||||
startTime = parseInt(global.lastItem.time) - 1;
|
startTime = global.nextTime;
|
||||||
url = "qute://history/data?start_time=" + startTime.toString();
|
url = "qute://history/data?start_time=" + startTime.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
getJSON(url, function(status, history) {
|
getJSON(url, function(status, history) {
|
||||||
if (history !== undefined) {
|
if (history !== undefined) {
|
||||||
for (item of history) {
|
for (item of history) {
|
||||||
|
if (item.next === -1) {
|
||||||
|
// Reached end of history
|
||||||
|
window.onscroll = null;
|
||||||
|
document.getElementById('eof').style.display = "block"
|
||||||
|
document.getElementById('load').style.display = "none"
|
||||||
|
continue;
|
||||||
|
} else if (item.next !== undefined) {
|
||||||
|
global.nextTime = parseInt(item.next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
atime = new Date(parseInt(item.time)*1000);
|
atime = new Date(parseInt(item.time)*1000);
|
||||||
var session = getSessionNode(atime);
|
var session = getSessionNode(atime);
|
||||||
var row = makeHistoryRow(item.url, item.title, atime.toLocaleTimeString());
|
var row = makeHistoryRow(item.url, item.title, atime.toLocaleTimeString());
|
||||||
@ -166,10 +192,11 @@ var loadHistory = function() {
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Browsing history</h1>
|
<h1>Browsing history</h1>
|
||||||
<div id="hist-container"></div>
|
<div id="hist-container"></div>
|
||||||
|
<span id="eof" style="display: none">end</span>
|
||||||
|
<a href="#" onclick="loadHistory();"id="load">Show more</a>
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
loadHistory();
|
loadHistory();
|
||||||
|
|
||||||
window.onscroll = function(ev) {
|
window.onscroll = function(ev) {
|
||||||
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
|
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
|
||||||
loadHistory();
|
loadHistory();
|
||||||
|
@ -64,10 +64,10 @@ class TestHistoryHandler:
|
|||||||
fake_web_history.save()
|
fake_web_history.save()
|
||||||
|
|
||||||
@pytest.mark.parametrize("start_time_offset, expected_item_count", [
|
@pytest.mark.parametrize("start_time_offset, expected_item_count", [
|
||||||
(0, 4),
|
(0, 5),
|
||||||
(24*60*60, 4),
|
(24*60*60, 5),
|
||||||
(48*60*60, 4),
|
(48*60*60, 5),
|
||||||
(72*60*60, 0)
|
(72*60*60, 1)
|
||||||
])
|
])
|
||||||
def test_qutehistory_data(self, start_time_offset, expected_item_count):
|
def test_qutehistory_data(self, start_time_offset, expected_item_count):
|
||||||
"""Ensure qute://history/data returns correct items."""
|
"""Ensure qute://history/data returns correct items."""
|
||||||
@ -78,11 +78,30 @@ class TestHistoryHandler:
|
|||||||
|
|
||||||
assert len(items) == expected_item_count
|
assert len(items) == expected_item_count
|
||||||
|
|
||||||
|
# test times
|
||||||
end_time = start_time - 24*60*60
|
end_time = start_time - 24*60*60
|
||||||
for item in items:
|
for item in items[:expected_item_count-1]:
|
||||||
assert item['time'] <= start_time
|
assert item['time'] <= start_time
|
||||||
assert item['time'] > end_time
|
assert item['time'] > end_time
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("start_time_offset, next_time", [
|
||||||
|
(0, 24*60*60),
|
||||||
|
(24*60*60, 48*60*60),
|
||||||
|
(48*60*60, -1),
|
||||||
|
(72*60*60, -1)
|
||||||
|
])
|
||||||
|
def test_qutehistory_next(self, start_time_offset, next_time):
|
||||||
|
"""Ensure qute://history/data returns correct items."""
|
||||||
|
start_time = int(self.now) - start_time_offset
|
||||||
|
url = QUrl("qute://history/data?start_time=" + str(start_time))
|
||||||
|
_mimetype, data = qutescheme.qute_history(url)
|
||||||
|
items = json.loads(data)
|
||||||
|
|
||||||
|
if next_time == -1:
|
||||||
|
assert items[-1]["next"] == -1
|
||||||
|
else:
|
||||||
|
assert items[-1]["next"] == int(self.now) - next_time
|
||||||
|
|
||||||
def test_qute_history_benchmark(self, fake_web_history, benchmark):
|
def test_qute_history_benchmark(self, fake_web_history, benchmark):
|
||||||
for t in range(100000): # one history per second
|
for t in range(100000): # one history per second
|
||||||
entry = history.Entry(
|
entry = history.Entry(
|
||||||
|
Loading…
Reference in New Issue
Block a user