Reduce calls to api to 12 at a time, instead of 20.

Remove Action local=true string and add it back to params removing
duplication, QML/Worker
Add checks at prepend to reduce duplicates. Worker.
This commit is contained in:
Mark Washeim 2022-12-22 21:32:49 +01:00
parent 2f88f1da59
commit 5f97137f4b
18 changed files with 139 additions and 18 deletions

View file

@ -72,7 +72,7 @@ function saveData() {
} }
} }
} }
console.log("ENF OF SAVING") console.log("END OF SAVING")
}); });
} }

View file

@ -46,10 +46,11 @@ var mastodonAPI = function(config) {
} }
} }
} }
queryStringAppend += "limit=12"
// ajax function // ajax function
var http = new XMLHttpRequest() var http = new XMLHttpRequest()
var url = apiBase + endpoint; var url = apiBase + endpoint;
console.log(queryStringAppend) console.log(apiBase + endpoint + queryStringAppend)
http.open("GET", apiBase + endpoint + queryStringAppend, true); http.open("GET", apiBase + endpoint + queryStringAppend, true);
// Send the proper header information along with the request // Send the proper header information along with the request

View file

@ -5,6 +5,7 @@ var loadImages = true;
// used to dedupe on append/insert // used to dedupe on append/insert
var knownIds = []; var knownIds = [];
var max_id ; var max_id ;
var since_id;
WorkerScript.onMessage = function(msg) { WorkerScript.onMessage = function(msg) {
/* /*
@ -16,9 +17,22 @@ WorkerScript.onMessage = function(msg) {
*/ */
// this is not elegant. it's max_id and ids from MyList // this is not elegant. it's max_id and ids from MyList
if (msg.params[1]) { if (msg.params[1]) {
if ( msg.params[0]["name"] === "max_id" ) {
max_id = msg.params[0]["data"] max_id = msg.params[0]["data"]
knownIds = msg.params[1]["data"] } else {
since_id = msg.params[0]["data"]
} }
// we don't want to pass it onto the backend
if ( msg.params[1]["name"] === "ids" ) {
knownIds = msg.params[1]["data"]
msg.params.pop()
}
if ( msg.params[2]["name"] === "ids" ) {
knownIds = msg.params[2]["data"]
msg.params.pop()
}
}
/** order notifications in ASC order */ /** order notifications in ASC order */
function orderNotifications(items){ function orderNotifications(items){
@ -130,30 +144,31 @@ WorkerScript.onMessage = function(msg) {
} }
} }
console.log("Get em all?")
if(msg.model && items.length) { if(msg.model && items.length) {
addDataToModel(msg.model, msg.mode, items) addDataToModel(msg.model, msg.mode, items)
WorkerScript.sendMessage({ 'updatedAll': true})
} }
/*if(msg.action === "notifications") /*if(msg.action === "notifications")
orderNotifications(items)*/ orderNotifications(items)*/
console.log("Get em all?")
WorkerScript.sendMessage({ 'updatedAll': true})
}); });
} }
//WorkerScript.sendMessage({ 'notifyNewItems': length - i }) //WorkerScript.sendMessage({ 'notifyNewItems': length - i })
function addDataToModel (model, mode, items) { function addDataToModel (model, mode, items) {
var length = items.length; var length = items.length;
console.log("Fetched > " +length + " in " + mode) console.log("Fetched > " +length + " in " + mode)
var i var i
if (mode === "append") { if (mode === "append") {
for(i = 0; i <= length-1; i++) { for(i = 0; i <= length-1; i++) {
if ( knownIds.indexOf( items[i]["id"]) === -1) { if ( knownIds.indexOf( items[i]["id"]) === -1) {
console.log("max: " + max_id + " i: " + items[i]["id"] + " known: " + knownIds[0]) if ( items[i]["id"] < max_id ) {
if ( items[i]["id"] < max_id && items[i]["id"] < knownIds[0]) {
model.append(items[i]) model.append(items[i])
} else { } else {
model.insert(0,items[i]) console.log("max: " + max_id + " i: " + items[i]["id"] + " known: " + knownIds[knownIds.length-1])
} }
} }
} }

View file

@ -78,7 +78,12 @@ SilicaListView {
pageStack.push(Qt.resolvedUrl("../SettingsPage.qml"), {}) pageStack.push(Qt.resolvedUrl("../SettingsPage.qml"), {})
} }
} }
MenuItem {
text: qsTr("Clear")
onClicked: {
clearLast()
}
}
MenuItem { MenuItem {
text: qsTr("New Toot") text: qsTr("New Toot")
visible: !profilePage visible: !profilePage
@ -156,9 +161,9 @@ SilicaListView {
openDrawer(contentY - scrollOffset > 0 ? false : true ) openDrawer(contentY - scrollOffset > 0 ? false : true )
scrollOffset = contentY scrollOffset = contentY
} }
if(contentY+height > footerItem.y && !loadStarted && autoLoadMore) { if(contentY+height > footerItem.y && !deduping && !loadStarted && autoLoadMore) {
loadData("append")
loadStarted = true loadStarted = true
loadData("append")
} }
} }
@ -182,7 +187,8 @@ SilicaListView {
// temporary debugging measure // temporary debugging measure
// should be resolved within loadData() // should be resolved within loadData()
if (messageObject.updatedAll){ if (messageObject.updatedAll){
if (model.count > 30) deDouble() if (debug) console.log("Got em all.")
if (model.count > 20) deDouble()
loadStarted = false loadStarted = false
} }
} }
@ -194,7 +200,20 @@ SilicaListView {
} }
Timer { Timer {
triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true triggeredOnStart: false;
interval: {
var listInterval = Math.floor(Math.random() * 60)*10*1000
if( title === "Home" ) listInterval = 20*60*1000
if( title === "Local" ) listInterval = 10*60*1000
if( title === "Federated" ) listInterval = 30*60*1000
if( title === "Bookmarks" ) listInterval = 40*60*1000
if( title === "Notifications" ) listInterval = 12*60*1000
if(debug) console.log(title + ' interval: ' + listInterval)
return listInterval
}
running: true;
repeat: true
onTriggered: { onTriggered: {
if(debug) console.log(title + ' ' + Date().toString()) if(debug) console.log(title + ' ' + Date().toString())
// let's avoid pre and appending at the same time! // let's avoid pre and appending at the same time!
@ -203,6 +222,7 @@ SilicaListView {
} }
/* /*
* NOT actually doing deduping :)
* utility called on updates to model to remove remove Duplicates: * utility called on updates to model to remove remove Duplicates:
* the dupes are probably a result of improper syncing of the models * the dupes are probably a result of improper syncing of the models
* this is temporary and can probaly be removed because of the * this is temporary and can probaly be removed because of the
@ -226,8 +246,16 @@ SilicaListView {
} }
//if (debug) console.log(ids) //if (debug) console.log(ids)
if (debug) console.log(uniqueItems.length) if (debug) console.log(uniqueItems.length)
if (debug) console.log( "maxminusone?:" + model.get(model.count - 2).id )
if (debug) console.log( "max?:" + model.get(model.count - 1).id )
if ( uniqueItems.length < model.count) { if ( uniqueItems.length < model.count) {
// it seems that only the last one, is an issue
/*if (model.get(model.count - 1).id > model.get(model.count - 2).id){
model.remove(model.count - 1,1)
}*/
if (debug) console.log(model.count) if (debug) console.log(model.count)
for(j = 0; j <= uniqueItems.length - 1 ; j++) { for(j = 0; j <= uniqueItems.length - 1 ; j++) {
seenIt = 0 seenIt = 0
@ -261,6 +289,23 @@ SilicaListView {
return unique; return unique;
} }
/* utility to clear last, debugging
*
*/
function clearLast() {
var msg = {
'action' : "CLEAR",
'model' : model,
'conf' : Logic.conf
}
//if (debug) console.log(JSON.stringify(msg))
if (model.count)
worker.sendMessage(msg)
}
/* Principle load function, uses websocket's worker.js /* Principle load function, uses websocket's worker.js
* *
*/ */
@ -288,11 +333,15 @@ SilicaListView {
if (mode === "prepend" && model.count) { if (mode === "prepend" && model.count) {
p.push({name:'since_id', data: model.get(0).id}) p.push({name:'since_id', data: model.get(0).id})
} }
//if (debug) console.log(JSON.stringify(uniqueIds))
if(title === "Local") {
type = "timelines/public"
p.push({name:'local', data: "true"})
}
// we push the ids via params which we remove in the WorkerScript
if (model.count) { if (model.count) {
p.push({name:'ids', data: uniqueIds}) p.push({name:'ids', data: uniqueIds})
} }
//if (debug) console.log(JSON.stringify(uniqueIds))
var msg = { var msg = {
'action' : type, 'action' : type,

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Nichts gefunden</translation> <translation>Nichts gefunden</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>No encontrado nada</translation> <translation>No encontrado nada</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Rien trouvé</translation> <translation>Rien trouvé</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Niente trovato</translation> <translation>Niente trovato</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Niets gevonden</translation> <translation>Niets gevonden</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Nic nie znaleziono</translation> <translation>Nic nie znaleziono</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Ничего не найдено</translation> <translation>Ничего не найдено</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Inget hittades</translation> <translation>Inget hittades</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>西</translation> <translation>西</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>

View file

@ -213,6 +213,10 @@
<source>Nothing found</source> <source>Nothing found</source>
<translation>Nothing found</translation> <translation>Nothing found</translation>
</message> </message>
<message>
<source>Clear</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>ProfileHeader</name> <name>ProfileHeader</name>