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
|
||||
|
||||
# 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:
|
||||
# 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_older = item.atime <= end_time
|
||||
if reverse:
|
||||
@ -189,6 +198,7 @@ def qute_history(url):
|
||||
# abort if item is older than start_time+24hr
|
||||
# skip if item is newer than start
|
||||
if item_older:
|
||||
yield {"next": int(item.atime)}
|
||||
return
|
||||
if item_newer:
|
||||
continue
|
||||
@ -198,15 +208,12 @@ def qute_history(url):
|
||||
# abort if item is newer than start_time
|
||||
# skip if item is older than start_time+24hrs
|
||||
if item_older:
|
||||
last_item = item
|
||||
continue
|
||||
if item_newer:
|
||||
yield {"next": int(last_item.atime)}
|
||||
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.
|
||||
item_url = item.url.toDisplayString()
|
||||
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}
|
||||
|
||||
# if we reached here, we had reached the end of history
|
||||
yield {"next": -1}
|
||||
|
||||
if url.path() == '/data':
|
||||
# Use start_time in query or current time.
|
||||
try:
|
||||
|
@ -28,6 +28,19 @@ table {
|
||||
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 {
|
||||
color: #aaa;
|
||||
height: 40px;
|
||||
@ -43,6 +56,8 @@ table {
|
||||
var global = {
|
||||
// The last history item that was seen.
|
||||
lastItem: null,
|
||||
// The next time to load
|
||||
nextTime: null,
|
||||
// The cutoff interval for session-separator (30 minutes)
|
||||
SESSION_CUTOFF: 30*60
|
||||
};
|
||||
@ -144,14 +159,25 @@ var getJSON = function(url, callback) {
|
||||
*/
|
||||
var loadHistory = function() {
|
||||
url = "qute://history/data";
|
||||
if (global.lastItem !== null) {
|
||||
startTime = parseInt(global.lastItem.time) - 1;
|
||||
if (global.nextTime !== null) {
|
||||
startTime = global.nextTime;
|
||||
url = "qute://history/data?start_time=" + startTime.toString();
|
||||
}
|
||||
|
||||
getJSON(url, function(status, history) {
|
||||
if (history !== undefined) {
|
||||
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);
|
||||
var session = getSessionNode(atime);
|
||||
var row = makeHistoryRow(item.url, item.title, atime.toLocaleTimeString());
|
||||
@ -166,10 +192,11 @@ var loadHistory = function() {
|
||||
{% block content %}
|
||||
<h1>Browsing history</h1>
|
||||
<div id="hist-container"></div>
|
||||
<span id="eof" style="display: none">end</span>
|
||||
<a href="#" onclick="loadHistory();"id="load">Show more</a>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
loadHistory();
|
||||
|
||||
window.onscroll = function(ev) {
|
||||
if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) {
|
||||
loadHistory();
|
||||
|
@ -64,10 +64,10 @@ class TestHistoryHandler:
|
||||
fake_web_history.save()
|
||||
|
||||
@pytest.mark.parametrize("start_time_offset, expected_item_count", [
|
||||
(0, 4),
|
||||
(24*60*60, 4),
|
||||
(48*60*60, 4),
|
||||
(72*60*60, 0)
|
||||
(0, 5),
|
||||
(24*60*60, 5),
|
||||
(48*60*60, 5),
|
||||
(72*60*60, 1)
|
||||
])
|
||||
def test_qutehistory_data(self, start_time_offset, expected_item_count):
|
||||
"""Ensure qute://history/data returns correct items."""
|
||||
@ -78,11 +78,30 @@ class TestHistoryHandler:
|
||||
|
||||
assert len(items) == expected_item_count
|
||||
|
||||
# test times
|
||||
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'] > 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):
|
||||
for t in range(100000): # one history per second
|
||||
entry = history.Entry(
|
||||
|
Loading…
Reference in New Issue
Block a user