Sped up some follower/following UI. But ultimately followed more people and made everything else slower.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3720 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2021-12-29 21:00:03 +00:00
parent f7974d2cef
commit 12010a84a3
5 changed files with 64 additions and 34 deletions

View File

@ -1 +1 @@
{"type":"tildefriends-app","files":{"app.js":"&LPDR4ZoE/qdPy9djmNFUfblXk7W1znMbwuAXp3/zWPI=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&uD6N8xUmrjXwIr95nkH/YjuZST6W1Q2MuJ8u6Vcmo6Q=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&Kf578HPfGnoog7LmW2Nof8dQldS04Opl26CE5+nsFLA=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}}
{"type":"tildefriends-app","files":{"app.js":"&jkL7crcAyW2KFUlHb43k+cY6JN9Ee3F0gy6ba4p70kg=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&taC9THJslxAMy72UIplFjALJx1VHv2l+qfjWoRhhrS4=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&u6n7Eqa1ryFuL9AhlYeJ/WzXYh6zxECKVfhG8/ecRM8=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}}

View File

@ -151,6 +151,7 @@ function fnv32a(value)
async function getRecentPostIds(db, id, ids, limit) {
const k_version = 9;
const k_batch_max = 8;
var o = await db.get(id + ':recent_posts');
var recent = [];
var f = o ? JSON.parse(o) : o;
@ -158,6 +159,15 @@ async function getRecentPostIds(db, id, ids, limit) {
if (!f || f.version != k_version || f.ids_hash != ids_hash) {
f = {recent: [], rowid: 0, version: k_version, ids_hash: ids_hash};
}
var row_id_max = 0;
await ssb.sqlStream(
"SELECT MAX(rowid) as rowid FROM messages ORDER BY timestamp DESC LIMIT ?",
[],
function(row) {
row_id_max = row.rowid;
});
for (var i = 0; i < ids.length; i += k_batch_max) {
var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length));
await ssb.sqlStream(
"SELECT "+
" rowid, "+
@ -166,19 +176,21 @@ async function getRecentPostIds(db, id, ids, limit) {
"FROM messages "+
"WHERE "+
" rowid > ? AND "+
" author IN (" + ids.map(x => '?').join(", ") + ") AND "+
" rowid <= ? AND "+
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
" json_extract(content, '$.type') IN ('post', 'tildefriends-app') "+
"UNION SELECT MAX(rowid) as rowid, NULL, NULL FROM messages "+
"ORDER BY timestamp DESC LIMIT ?",
[].concat([f.rowid], ids, [limit + 1]),
[].concat([f.rowid, row_id_max], ids_batch, [limit]),
function(row) {
if (row.id) {
recent.push(row.id);
}
if (row.rowid) {
f.rowid = row.rowid;
f.rowid = Math.max(row.rowid, f.rowid);
}
});
}
f.recent.sort((x, y) => x.timestamp - y.timestamp);
f.recent = [].concat(recent, f.recent).slice(0, limit);
var j = JSON.stringify(f);
if (o != j) {

View File

@ -13,16 +13,22 @@ Vue.component('tf-user', {
computed: {
following: {
get: function() {
return g_data.users[g_data.whoami] &&
g_data.users[g_data.whoami].following &&
g_data.users[g_data.whoami].following.indexOf(this.id) != -1;
return g_data.users &&
g_data.users[g_data.whoami] &&
g_data.users[g_data.whoami].following[this.id];
},
set: function(newValue) {
if (g_data.users[g_data.whoami] &&
g_data.users[g_data.whoami].following) {
if (newValue && g_data.users[g_data.whoami].following.indexOf(this.id) == -1) {
var already_following =
g_data.users &&
g_data.users[g_data.whoami] &&
g_data.users[g_data.whoami].following &&
g_data.users[g_data.whoami].following[this.id];
if (newValue && !already_following) {
if (confirm("Are you sure you want to follow " + this.id + "?")) {
window.parent.postMessage({appendMessage: {type: "contact", following: true, contact: this.id}}, '*');
} else if (!newValue) {
}
} else if (!newValue && already_following) {
if (confirm("Are you sure you want to unfollow " + this.id + "?")) {
window.parent.postMessage({appendMessage: {type: "contact", following: false, contact: this.id}}, '*');
}
}
@ -49,8 +55,10 @@ Vue.component('tf-user', {
}
},
},
template: `<span @click="show_user()">
template: `<span>
<md-chip md-clickable :class="following ? 'md-accent' : ''" @click="show_user()">
{{users[id] && users[id].name ? users[id].name : id}}
</md-chip>
<md-tooltip v-if="users[id] && users[id].name">{{id}}</md-tooltip>
<md-dialog :md-active.sync="show_user_dialog">
<md-dialog-title>{{users[id] && users[id].name ? users[id].name : id}}</md-dialog-title>
@ -72,18 +80,18 @@ Vue.component('tf-user', {
<div><md-switch v-model="following">Following</md-switch></div>
<md-list>
<md-subheader>Followers</md-subheader>
<md-list-item v-for="follower in (users[id] || []).followers" v-bind:key="'follower-' + follower">
<md-list-item v-for="follower in Object.keys((users[id] && users[id].followers) ? users[id].followers : {})" v-bind:key="'follower-' + follower">
<tf-user :id="follower"></tf-user>
</md-list-item>
<md-subheader>Following</md-subheader>
<md-list-item v-for="user in (users[id] || []).following" v-bind:key="'following-' + user">
<md-list-item v-for="user in Object.keys((users[id] && users[id].following) ? users[id].following : {})" v-bind:key="'following-' + user">
<tf-user :id="user"></tf-user>
</md-list-item>
</md-list>
</template>
</md-dialog-content>
<md-dialog-actions>
<md-button @click="save_profile">Save Profile</md-button>
<md-button @click="save_profile" v-if="id == whoami">Save Profile</md-button>
<md-button @click="show_user_dialog = false">Close</md-button>
</md-dialog-actions>
</md-dialog>

View File

@ -55,12 +55,22 @@ function processMessages() {
if (!g_data.users[event.data.followers.id]) {
Vue.set(g_data.users, event.data.followers.id, {});
}
Vue.set(g_data.users[event.data.followers.id], 'followers', event.data.followers.users);
if (!g_data.users[event.data.followers.id].followers) {
Vue.set(g_data.users[event.data.followers.id], 'followers', {});
}
for (let user of event.data.followers.users) {
Vue.set(g_data.users[event.data.followers.id].followers, user, true);
}
} else if (key == 'following') {
if (!g_data.users[event.data.following.id]) {
Vue.set(g_data.users, event.data.following.id, {});
}
Vue.set(g_data.users[event.data.following.id], 'following', event.data.following.users);
if (!g_data.users[event.data.following.id].following) {
Vue.set(g_data.users[event.data.following.id], 'following', {});
}
for (let user of event.data.following.users) {
Vue.set(g_data.users[event.data.following.id].following, user, true);
}
} else if (key == 'broadcasts') {
g_data.broadcasts = event.data.broadcasts;
} else if (key == 'pubs') {

View File

@ -457,7 +457,7 @@ void tf_ssb_db_visit_query(tf_ssb_t* ssb, const char* query, const JSValue binds
}
else
{
printf("prepare failed: %s\n", sqlite3_errmsg(db));
printf("prepare failed: %s: %s\n", sqlite3_errmsg(db), query);
}
sqlite3_set_authorizer(db, NULL, NULL);
}