From 5f97137f4b347be31fff5d622170538795435c5c Mon Sep 17 00:00:00 2001 From: Mark Washeim Date: Thu, 22 Dec 2022 21:32:49 +0100 Subject: [PATCH] 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. --- qml/lib/API.js | 2 +- qml/lib/Mastodon.js | 3 +- qml/lib/Worker.js | 31 +++++++++---- qml/pages/components/MyList.qml | 65 +++++++++++++++++++++++---- translations/harbour-tooterb-de.ts | 4 ++ translations/harbour-tooterb-el.ts | 4 ++ translations/harbour-tooterb-es.ts | 4 ++ translations/harbour-tooterb-fr.ts | 4 ++ translations/harbour-tooterb-it.ts | 4 ++ translations/harbour-tooterb-nl.ts | 4 ++ translations/harbour-tooterb-nl_BE.ts | 4 ++ translations/harbour-tooterb-oc.ts | 4 ++ translations/harbour-tooterb-pl.ts | 4 ++ translations/harbour-tooterb-ru.ts | 4 ++ translations/harbour-tooterb-sr.ts | 4 ++ translations/harbour-tooterb-sv.ts | 4 ++ translations/harbour-tooterb-zh_CN.ts | 4 ++ translations/harbour-tooterb.ts | 4 ++ 18 files changed, 139 insertions(+), 18 deletions(-) diff --git a/qml/lib/API.js b/qml/lib/API.js index f2a4a40..0af167e 100644 --- a/qml/lib/API.js +++ b/qml/lib/API.js @@ -72,7 +72,7 @@ function saveData() { } } } - console.log("ENF OF SAVING") + console.log("END OF SAVING") }); } diff --git a/qml/lib/Mastodon.js b/qml/lib/Mastodon.js index 97b5bcc..07646df 100644 --- a/qml/lib/Mastodon.js +++ b/qml/lib/Mastodon.js @@ -46,10 +46,11 @@ var mastodonAPI = function(config) { } } } + queryStringAppend += "limit=12" // ajax function var http = new XMLHttpRequest() var url = apiBase + endpoint; - console.log(queryStringAppend) + console.log(apiBase + endpoint + queryStringAppend) http.open("GET", apiBase + endpoint + queryStringAppend, true); // Send the proper header information along with the request diff --git a/qml/lib/Worker.js b/qml/lib/Worker.js index d4345f9..fd965fd 100644 --- a/qml/lib/Worker.js +++ b/qml/lib/Worker.js @@ -5,6 +5,7 @@ var loadImages = true; // used to dedupe on append/insert var knownIds = []; var max_id ; +var since_id; WorkerScript.onMessage = function(msg) { /* @@ -16,10 +17,23 @@ WorkerScript.onMessage = function(msg) { */ // this is not elegant. it's max_id and ids from MyList if (msg.params[1]) { - max_id = msg.params[0]["data"] - knownIds = msg.params[1]["data"] + if ( msg.params[0]["name"] === "max_id" ) { + max_id = msg.params[0]["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 */ function orderNotifications(items){ for (var i = items.length-1; i > 0; i--) { @@ -130,30 +144,31 @@ WorkerScript.onMessage = function(msg) { } } - console.log("Get em all?") if(msg.model && items.length) { addDataToModel(msg.model, msg.mode, items) - WorkerScript.sendMessage({ 'updatedAll': true}) } /*if(msg.action === "notifications") orderNotifications(items)*/ + console.log("Get em all?") + WorkerScript.sendMessage({ 'updatedAll': true}) }); } //WorkerScript.sendMessage({ 'notifyNewItems': length - i }) + function addDataToModel (model, mode, items) { var length = items.length; console.log("Fetched > " +length + " in " + mode) var i if (mode === "append") { + for(i = 0; i <= length-1; i++) { 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 && items[i]["id"] < knownIds[0]) { + if ( items[i]["id"] < max_id ) { model.append(items[i]) - } else { - model.insert(0,items[i]) + } else { + console.log("max: " + max_id + " i: " + items[i]["id"] + " known: " + knownIds[knownIds.length-1]) } } } diff --git a/qml/pages/components/MyList.qml b/qml/pages/components/MyList.qml index 5ec5179..54e8f6e 100644 --- a/qml/pages/components/MyList.qml +++ b/qml/pages/components/MyList.qml @@ -78,7 +78,12 @@ SilicaListView { pageStack.push(Qt.resolvedUrl("../SettingsPage.qml"), {}) } } - + MenuItem { + text: qsTr("Clear") + onClicked: { + clearLast() + } + } MenuItem { text: qsTr("New Toot") visible: !profilePage @@ -156,9 +161,9 @@ SilicaListView { openDrawer(contentY - scrollOffset > 0 ? false : true ) scrollOffset = contentY } - if(contentY+height > footerItem.y && !loadStarted && autoLoadMore) { - loadData("append") + if(contentY+height > footerItem.y && !deduping && !loadStarted && autoLoadMore) { loadStarted = true + loadData("append") } } @@ -182,7 +187,8 @@ SilicaListView { // temporary debugging measure // should be resolved within loadData() if (messageObject.updatedAll){ - if (model.count > 30) deDouble() + if (debug) console.log("Got em all.") + if (model.count > 20) deDouble() loadStarted = false } } @@ -194,15 +200,29 @@ SilicaListView { } 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: { - if(debug) console.log(title + ' ' +Date().toString()) + if(debug) console.log(title + ' ' + Date().toString()) // let's avoid pre and appending at the same time! if ( ! loadStarted && ! deduping ) loadData("prepend") } } /* + * NOT actually doing deduping :) * utility called on updates to model to remove remove Duplicates: * the dupes are probably a result of improper syncing of the models * 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(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) { + + // 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) for(j = 0; j <= uniqueItems.length - 1 ; j++) { seenIt = 0 @@ -261,6 +289,23 @@ SilicaListView { 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 * */ @@ -288,11 +333,15 @@ SilicaListView { if (mode === "prepend" && model.count) { 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) { p.push({name:'ids', data: uniqueIds}) } - //if (debug) console.log(JSON.stringify(uniqueIds)) var msg = { 'action' : type, diff --git a/translations/harbour-tooterb-de.ts b/translations/harbour-tooterb-de.ts index 607e9a4..e7196b4 100644 --- a/translations/harbour-tooterb-de.ts +++ b/translations/harbour-tooterb-de.ts @@ -213,6 +213,10 @@ Nothing found Nichts gefunden + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-el.ts b/translations/harbour-tooterb-el.ts index c397e1d..212f992 100644 --- a/translations/harbour-tooterb-el.ts +++ b/translations/harbour-tooterb-el.ts @@ -213,6 +213,10 @@ Nothing found + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-es.ts b/translations/harbour-tooterb-es.ts index 9d96657..a67b993 100644 --- a/translations/harbour-tooterb-es.ts +++ b/translations/harbour-tooterb-es.ts @@ -213,6 +213,10 @@ Nothing found No encontrado nada + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-fr.ts b/translations/harbour-tooterb-fr.ts index 8e4ad82..b1d61ac 100644 --- a/translations/harbour-tooterb-fr.ts +++ b/translations/harbour-tooterb-fr.ts @@ -213,6 +213,10 @@ Nothing found Rien trouvé + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-it.ts b/translations/harbour-tooterb-it.ts index 30ac17f..6b01189 100644 --- a/translations/harbour-tooterb-it.ts +++ b/translations/harbour-tooterb-it.ts @@ -213,6 +213,10 @@ Nothing found Niente trovato + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-nl.ts b/translations/harbour-tooterb-nl.ts index a5b6f76..9d735a3 100644 --- a/translations/harbour-tooterb-nl.ts +++ b/translations/harbour-tooterb-nl.ts @@ -213,6 +213,10 @@ Nothing found Niets gevonden + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-nl_BE.ts b/translations/harbour-tooterb-nl_BE.ts index 7792bf9..507be12 100644 --- a/translations/harbour-tooterb-nl_BE.ts +++ b/translations/harbour-tooterb-nl_BE.ts @@ -213,6 +213,10 @@ Nothing found + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-oc.ts b/translations/harbour-tooterb-oc.ts index ee636dc..ca9abbb 100644 --- a/translations/harbour-tooterb-oc.ts +++ b/translations/harbour-tooterb-oc.ts @@ -213,6 +213,10 @@ Nothing found + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-pl.ts b/translations/harbour-tooterb-pl.ts index c1dda8f..435d717 100644 --- a/translations/harbour-tooterb-pl.ts +++ b/translations/harbour-tooterb-pl.ts @@ -213,6 +213,10 @@ Nothing found Nic nie znaleziono + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-ru.ts b/translations/harbour-tooterb-ru.ts index c082582..0c47889 100644 --- a/translations/harbour-tooterb-ru.ts +++ b/translations/harbour-tooterb-ru.ts @@ -213,6 +213,10 @@ Nothing found Ничего не найдено + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-sr.ts b/translations/harbour-tooterb-sr.ts index 39bd8b0..c0cb387 100644 --- a/translations/harbour-tooterb-sr.ts +++ b/translations/harbour-tooterb-sr.ts @@ -213,6 +213,10 @@ Nothing found + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-sv.ts b/translations/harbour-tooterb-sv.ts index 2f28c5b..0fbb418 100644 --- a/translations/harbour-tooterb-sv.ts +++ b/translations/harbour-tooterb-sv.ts @@ -213,6 +213,10 @@ Nothing found Inget hittades + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb-zh_CN.ts b/translations/harbour-tooterb-zh_CN.ts index fa6d895..af2b4fb 100644 --- a/translations/harbour-tooterb-zh_CN.ts +++ b/translations/harbour-tooterb-zh_CN.ts @@ -213,6 +213,10 @@ Nothing found 没有发现任何东西 + + Clear + + ProfileHeader diff --git a/translations/harbour-tooterb.ts b/translations/harbour-tooterb.ts index 42f8869..097fe45 100644 --- a/translations/harbour-tooterb.ts +++ b/translations/harbour-tooterb.ts @@ -213,6 +213,10 @@ Nothing found Nothing found + + Clear + + ProfileHeader