Load friendsList/userDialog stats with single query

This commit is contained in:
Natsumi
2022-02-11 12:21:26 +13:00
parent a8f95a443d
commit bccfd2fd0c
2 changed files with 40 additions and 26 deletions

View File

@@ -12710,19 +12710,11 @@ speechSynthesis.getVoices();
if (this.lastLocation.playerList.has(D.ref.displayName)) {
inCurrentWorld = true;
}
database.getLastSeen(D.ref, inCurrentWorld).then((ref1) => {
database.getUserStats(D.ref, inCurrentWorld).then((ref1) => {
if (ref1.userId === D.id) {
D.lastSeen = ref1.created_at;
}
});
database.getJoinCount(D.ref).then((ref2) => {
if (ref2.userId === D.id) {
D.joinCount = ref2.joinCount;
}
});
database.getTimeSpent(D.ref).then((ref3) => {
if (ref3.userId === D.id) {
D.timeSpent = ref3.timeSpent;
D.joinCount = ref1.joinCount;
D.timeSpent = ref1.timeSpent;
}
});
}
@@ -16034,30 +16026,22 @@ speechSynthesis.getVoices();
continue;
}
}
this.getJoinCount(ctx.ref);
this.getLastSeen(ctx.ref);
this.getTimeSpent(ctx.ref);
var inCurrentWorld = false;
if (this.lastLocation.playerList.has(ctx.ref.displayName)) {
inCurrentWorld = true;
}
this.getUserStats(ctx.ref);
ctx.ref.$friendNum = ctx.no;
results.push(ctx.ref);
}
this.friendsListTable.data = results;
};
$app.methods.getJoinCount = async function (ctx) {
var ref = await database.getJoinCount(ctx);
$app.methods.getUserStats = async function (ctx) {
var ref = await database.getUserStats(ctx);
// eslint-disable-next-line require-atomic-updates
ctx.$joinCount = ref.joinCount;
};
$app.methods.getLastSeen = async function (ctx) {
var ref = await database.getLastSeen(ctx);
// eslint-disable-next-line require-atomic-updates
ctx.$lastSeen = ref.created_at;
};
$app.methods.getTimeSpent = async function (ctx) {
var ref = await database.getTimeSpent(ctx);
// eslint-disable-next-line require-atomic-updates
ctx.$timeSpent = ref.timeSpent;
};

View File

@@ -873,6 +873,36 @@ class Database {
return ref;
}
async getUserStats(input, inCurrentWorld) {
var i = 0;
var instances = new Set();
var ref = {
timeSpent: 0,
created_at: '',
joinCount: 0,
userId: input.id
};
await sqliteService.execute(
(row) => {
if (typeof row[2] === 'number') {
ref.timeSpent += row[2];
}
i++;
if (i === 1 || (inCurrentWorld && i === 2)) {
ref.created_at = row[0];
}
instances.add(row[3]);
},
`SELECT created_at, user_id, time, location FROM gamelog_join_leave WHERE user_id = @userId OR display_name = @displayName ORDER BY id DESC`,
{
'@userId': input.id,
'@displayName': input.displayName
}
);
ref.joinCount = instances.size;
return ref;
}
async lookupFeedDatabase(search, filters, vipList) {
var search = search.replaceAll("'", "''");
var vipQuery = '';