mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 14:46:04 +02:00
improve gamelog sql
This commit is contained in:
+334
-116
@@ -663,24 +663,31 @@ const gameLog = {
|
|||||||
return gamelogDatabase;
|
return gamelogDatabase;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup the game log database for a specific search term
|
|
||||||
* @param {string} search The search term
|
|
||||||
* @param {Array} filters The filters to apply
|
|
||||||
* @param {Array} [vipList] The list of VIP users
|
|
||||||
* @returns {Promise<any[]>} The game log data
|
|
||||||
*/
|
|
||||||
|
|
||||||
async lookupGameLogDatabase(
|
async lookupGameLogDatabase(
|
||||||
search,
|
|
||||||
filters,
|
filters,
|
||||||
vipList,
|
vipList,
|
||||||
maxEntries = dbVars.maxTableSize
|
maxEntries = dbVars.maxTableSize
|
||||||
) {
|
) {
|
||||||
search = search.replaceAll("'", "''");
|
const baseColumns = [
|
||||||
if (search.startsWith('wrld_') || search.startsWith('grp_')) {
|
'id',
|
||||||
return this.getGameLogByLocation(search, filters);
|
'created_at',
|
||||||
}
|
'type',
|
||||||
|
'display_name',
|
||||||
|
'location',
|
||||||
|
'user_id',
|
||||||
|
'time',
|
||||||
|
'world_id',
|
||||||
|
'world_name',
|
||||||
|
'group_name',
|
||||||
|
'instance_id',
|
||||||
|
'video_url',
|
||||||
|
'video_name',
|
||||||
|
'video_id',
|
||||||
|
'resource_url',
|
||||||
|
'resource_type',
|
||||||
|
'data',
|
||||||
|
'message'
|
||||||
|
].join(', ');
|
||||||
let vipQuery = '';
|
let vipQuery = '';
|
||||||
if (vipList.length > 0) {
|
if (vipList.length > 0) {
|
||||||
vipQuery = 'AND user_id IN (';
|
vipQuery = 'AND user_id IN (';
|
||||||
@@ -692,15 +699,15 @@ const gameLog = {
|
|||||||
}
|
}
|
||||||
vipQuery += ')';
|
vipQuery += ')';
|
||||||
}
|
}
|
||||||
var location = true;
|
let location = true;
|
||||||
var onplayerjoined = true;
|
let onplayerjoined = true;
|
||||||
var onplayerleft = true;
|
let onplayerleft = true;
|
||||||
var portalspawn = true;
|
let portalspawn = true;
|
||||||
var msgevent = true;
|
let msgevent = true;
|
||||||
var external = true;
|
let external = true;
|
||||||
var videoplay = true;
|
let videoplay = true;
|
||||||
var resourceload_string = true;
|
let resourceload_string = true;
|
||||||
var resourceload_image = true;
|
let resourceload_image = true;
|
||||||
if (filters.length > 0) {
|
if (filters.length > 0) {
|
||||||
location = false;
|
location = false;
|
||||||
onplayerjoined = false;
|
onplayerjoined = false;
|
||||||
@@ -743,24 +750,14 @@ const gameLog = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var gamelogDatabase = [];
|
const selects = [];
|
||||||
if (location) {
|
if (location) {
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, 'Location' AS type, NULL AS display_name, location, NULL AS user_id, time, world_id, world_name, group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_location ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: 'Location',
|
|
||||||
location: dbRow[2],
|
|
||||||
worldId: dbRow[3],
|
|
||||||
worldName: dbRow[4],
|
|
||||||
time: dbRow[5],
|
|
||||||
groupName: dbRow[6]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_location WHERE world_name LIKE '%${search}%' OR group_name LIKE '%${search}%' ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (onplayerjoined || onplayerleft) {
|
if (onplayerjoined || onplayerleft) {
|
||||||
var query = '';
|
let query = '';
|
||||||
if (!onplayerjoined || !onplayerleft) {
|
if (!onplayerjoined || !onplayerleft) {
|
||||||
if (onplayerjoined) {
|
if (onplayerjoined) {
|
||||||
query = "AND type = 'OnPlayerJoined'";
|
query = "AND type = 'OnPlayerJoined'";
|
||||||
@@ -768,110 +765,331 @@ const gameLog = {
|
|||||||
query = "AND type = 'OnPlayerLeft'";
|
query = "AND type = 'OnPlayerLeft'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, type, display_name, location, user_id, time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_join_leave WHERE 1=1 ${vipQuery} ${query} ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: dbRow[2],
|
|
||||||
displayName: dbRow[3],
|
|
||||||
location: dbRow[4],
|
|
||||||
userId: dbRow[5],
|
|
||||||
time: dbRow[6]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_join_leave WHERE (display_name LIKE '%${search}%' AND user_id != '${dbVars.userId}') ${vipQuery} ${query} ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (portalspawn) {
|
if (portalspawn) {
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, 'PortalSpawn' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, world_name, NULL AS group_name, instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_portal_spawn WHERE 1=1 ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: 'PortalSpawn',
|
|
||||||
displayName: dbRow[2],
|
|
||||||
location: dbRow[3],
|
|
||||||
userId: dbRow[4],
|
|
||||||
instanceId: dbRow[5],
|
|
||||||
worldName: dbRow[6]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_portal_spawn WHERE (display_name LIKE '%${search}%' OR world_name LIKE '%${search}%') ${vipQuery} ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (msgevent) {
|
if (msgevent) {
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, 'Event' AS type, NULL AS display_name, NULL AS location, NULL AS user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, data, NULL AS message FROM gamelog_event ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: 'Event',
|
|
||||||
data: dbRow[2]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_event WHERE data LIKE '%${search}%' ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (external) {
|
if (external) {
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, 'External' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, message FROM gamelog_external WHERE 1=1 ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: 'External',
|
|
||||||
message: dbRow[2],
|
|
||||||
displayName: dbRow[3],
|
|
||||||
userId: dbRow[4],
|
|
||||||
location: dbRow[5]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_external WHERE (display_name LIKE '%${search}%' OR message LIKE '%${search}%') ${vipQuery} ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (videoplay) {
|
if (videoplay) {
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, 'VideoPlay' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, video_url, video_name, video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_video_play WHERE 1=1 ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
rowId: dbRow[0],
|
);
|
||||||
created_at: dbRow[1],
|
|
||||||
type: 'VideoPlay',
|
|
||||||
videoUrl: dbRow[2],
|
|
||||||
videoName: dbRow[3],
|
|
||||||
videoId: dbRow[4],
|
|
||||||
location: dbRow[5],
|
|
||||||
displayName: dbRow[6],
|
|
||||||
userId: dbRow[7]
|
|
||||||
};
|
|
||||||
gamelogDatabase.push(row);
|
|
||||||
}, `SELECT * FROM gamelog_video_play WHERE (video_url LIKE '%${search}%' OR video_name LIKE '%${search}%' OR display_name LIKE '%${search}%') ${vipQuery} ORDER BY id DESC LIMIT ${maxEntries}`);
|
|
||||||
}
|
}
|
||||||
if (resourceload_string || resourceload_image) {
|
if (resourceload_string || resourceload_image) {
|
||||||
var checkString = '';
|
let checkString = '';
|
||||||
var checkImage = '';
|
let checkImage = '';
|
||||||
if (!resourceload_string) {
|
if (!resourceload_string) {
|
||||||
checkString = `AND resource_type != 'StringLoad'`;
|
checkString = `AND resource_type != 'StringLoad'`;
|
||||||
}
|
}
|
||||||
if (!resourceload_image) {
|
if (!resourceload_image) {
|
||||||
checkString = `AND resource_type != 'ImageLoad'`;
|
checkString = `AND resource_type != 'ImageLoad'`;
|
||||||
}
|
}
|
||||||
await sqliteService.execute((dbRow) => {
|
selects.push(
|
||||||
var row = {
|
`SELECT * FROM (SELECT id, created_at, resource_type AS type, NULL AS display_name, location, NULL AS user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, resource_url, resource_type, NULL AS data, NULL AS message FROM gamelog_resource_load WHERE 1=1 ${checkString} ${checkImage} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (selects.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const gamelogDatabase = [];
|
||||||
|
const args = {
|
||||||
|
'@limit': maxEntries,
|
||||||
|
'@perTable': maxEntries
|
||||||
|
};
|
||||||
|
await sqliteService.execute(
|
||||||
|
(dbRow) => {
|
||||||
|
const row = {
|
||||||
rowId: dbRow[0],
|
rowId: dbRow[0],
|
||||||
created_at: dbRow[1],
|
created_at: dbRow[1],
|
||||||
type: dbRow[3],
|
type: dbRow[2]
|
||||||
resourceUrl: dbRow[2],
|
|
||||||
location: dbRow[4]
|
|
||||||
};
|
};
|
||||||
|
switch (dbRow[2]) {
|
||||||
|
case 'Location':
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.worldId = dbRow[7];
|
||||||
|
row.worldName = dbRow[8];
|
||||||
|
row.time = dbRow[6];
|
||||||
|
row.groupName = dbRow[9];
|
||||||
|
break;
|
||||||
|
case 'OnPlayerJoined':
|
||||||
|
case 'OnPlayerLeft':
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.time = dbRow[6];
|
||||||
|
break;
|
||||||
|
case 'PortalSpawn':
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.instanceId = dbRow[10];
|
||||||
|
row.worldName = dbRow[8];
|
||||||
|
break;
|
||||||
|
case 'VideoPlay':
|
||||||
|
row.videoUrl = dbRow[11];
|
||||||
|
row.videoName = dbRow[12];
|
||||||
|
row.videoId = dbRow[13];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
break;
|
||||||
|
case 'Event':
|
||||||
|
row.data = dbRow[16];
|
||||||
|
break;
|
||||||
|
case 'External':
|
||||||
|
row.message = dbRow[17];
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
break;
|
||||||
|
case 'StringLoad':
|
||||||
|
case 'ImageLoad':
|
||||||
|
row.resourceUrl = dbRow[14];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
break;
|
||||||
|
}
|
||||||
gamelogDatabase.push(row);
|
gamelogDatabase.push(row);
|
||||||
}, `SELECT * FROM gamelog_resource_load WHERE resource_url LIKE '%${search}%' ${checkString} ${checkImage} ORDER BY id DESC LIMIT ${maxEntries}`);
|
},
|
||||||
|
`SELECT ${baseColumns} FROM (${selects.join(' UNION ALL ')}) ORDER BY created_at DESC, id DESC LIMIT @limit`,
|
||||||
|
args
|
||||||
|
);
|
||||||
|
return gamelogDatabase;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup the game log database for a specific search term
|
||||||
|
* @param {string} search The search term
|
||||||
|
* @param {Array} filters The filters to apply
|
||||||
|
* @param {Array} [vipList] The list of VIP users
|
||||||
|
* @returns {Promise<any[]>} The game log data
|
||||||
|
*/
|
||||||
|
|
||||||
|
async searchGameLogDatabase(
|
||||||
|
search,
|
||||||
|
filters,
|
||||||
|
vipList,
|
||||||
|
maxEntries = dbVars.maxTableSize
|
||||||
|
) {
|
||||||
|
if (search.startsWith('wrld_') || search.startsWith('grp_')) {
|
||||||
|
return this.getGameLogByLocation(search, filters);
|
||||||
}
|
}
|
||||||
var compareByCreatedAt = function (a, b) {
|
let vipQuery = '';
|
||||||
var A = a.created_at;
|
const vipArgs = {};
|
||||||
var B = b.created_at;
|
if (vipList.length > 0) {
|
||||||
if (A < B) {
|
const vipPlaceholders = [];
|
||||||
return -1;
|
vipList.forEach((vip, i) => {
|
||||||
|
const key = `@vip_${i}`;
|
||||||
|
vipArgs[key] = vip;
|
||||||
|
vipPlaceholders.push(key);
|
||||||
|
});
|
||||||
|
vipQuery = `AND user_id IN (${vipPlaceholders.join(', ')})`;
|
||||||
}
|
}
|
||||||
if (A > B) {
|
let location = true;
|
||||||
return 1;
|
let onplayerjoined = true;
|
||||||
|
let onplayerleft = true;
|
||||||
|
let portalspawn = true;
|
||||||
|
let msgevent = true;
|
||||||
|
let external = true;
|
||||||
|
let videoplay = true;
|
||||||
|
let resourceload_string = true;
|
||||||
|
let resourceload_image = true;
|
||||||
|
if (filters.length > 0) {
|
||||||
|
location = false;
|
||||||
|
onplayerjoined = false;
|
||||||
|
onplayerleft = false;
|
||||||
|
portalspawn = false;
|
||||||
|
msgevent = false;
|
||||||
|
external = false;
|
||||||
|
videoplay = false;
|
||||||
|
resourceload_string = false;
|
||||||
|
resourceload_image = false;
|
||||||
|
filters.forEach((filter) => {
|
||||||
|
switch (filter) {
|
||||||
|
case 'Location':
|
||||||
|
location = true;
|
||||||
|
break;
|
||||||
|
case 'OnPlayerJoined':
|
||||||
|
onplayerjoined = true;
|
||||||
|
break;
|
||||||
|
case 'OnPlayerLeft':
|
||||||
|
onplayerleft = true;
|
||||||
|
break;
|
||||||
|
case 'PortalSpawn':
|
||||||
|
portalspawn = true;
|
||||||
|
break;
|
||||||
|
case 'Event':
|
||||||
|
msgevent = true;
|
||||||
|
break;
|
||||||
|
case 'External':
|
||||||
|
external = true;
|
||||||
|
break;
|
||||||
|
case 'VideoPlay':
|
||||||
|
videoplay = true;
|
||||||
|
break;
|
||||||
|
case 'StringLoad':
|
||||||
|
resourceload_string = true;
|
||||||
|
break;
|
||||||
|
case 'ImageLoad':
|
||||||
|
resourceload_image = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
});
|
||||||
|
}
|
||||||
|
const searchLike = `%${search}%`;
|
||||||
|
const selects = [];
|
||||||
|
const baseColumns = [
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'type',
|
||||||
|
'display_name',
|
||||||
|
'location',
|
||||||
|
'user_id',
|
||||||
|
'time',
|
||||||
|
'world_id',
|
||||||
|
'world_name',
|
||||||
|
'group_name',
|
||||||
|
'instance_id',
|
||||||
|
'video_url',
|
||||||
|
'video_name',
|
||||||
|
'video_id',
|
||||||
|
'resource_url',
|
||||||
|
'resource_type',
|
||||||
|
'data',
|
||||||
|
'message'
|
||||||
|
].join(', ');
|
||||||
|
if (location) {
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, 'Location' AS type, NULL AS display_name, location, NULL AS user_id, time, world_id, world_name, group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_location WHERE (world_name LIKE @searchLike OR group_name LIKE @searchLike) ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (onplayerjoined || onplayerleft) {
|
||||||
|
let query = '';
|
||||||
|
if (!onplayerjoined || !onplayerleft) {
|
||||||
|
if (onplayerjoined) {
|
||||||
|
query = "AND type = 'OnPlayerJoined'";
|
||||||
|
} else if (onplayerleft) {
|
||||||
|
query = "AND type = 'OnPlayerLeft'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, type, display_name, location, user_id, time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_join_leave WHERE (display_name LIKE @searchLike AND user_id != '${dbVars.userId}') ${vipQuery} ${query} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (portalspawn) {
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, 'PortalSpawn' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, world_name, NULL AS group_name, instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_portal_spawn WHERE (display_name LIKE @searchLike OR world_name LIKE @searchLike) ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (msgevent) {
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, 'Event' AS type, NULL AS display_name, NULL AS location, NULL AS user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, data, NULL AS message FROM gamelog_event WHERE data LIKE @searchLike ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (external) {
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, 'External' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, message FROM gamelog_external WHERE (display_name LIKE @searchLike OR message LIKE @searchLike) ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (videoplay) {
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, 'VideoPlay' AS type, display_name, location, user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, video_url, video_name, video_id, NULL AS resource_url, NULL AS resource_type, NULL AS data, NULL AS message FROM gamelog_video_play WHERE (video_url LIKE @searchLike OR video_name LIKE @searchLike OR display_name LIKE @searchLike) ${vipQuery} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (resourceload_string || resourceload_image) {
|
||||||
|
let checkString = '';
|
||||||
|
let checkImage = '';
|
||||||
|
if (!resourceload_string) {
|
||||||
|
checkString = `AND resource_type != 'StringLoad'`;
|
||||||
|
}
|
||||||
|
if (!resourceload_image) {
|
||||||
|
checkString = `AND resource_type != 'ImageLoad'`;
|
||||||
|
}
|
||||||
|
selects.push(
|
||||||
|
`SELECT * FROM (SELECT id, created_at, resource_type AS type, NULL AS display_name, location, NULL AS user_id, NULL AS time, NULL AS world_id, NULL AS world_name, NULL AS group_name, NULL AS instance_id, NULL AS video_url, NULL AS video_name, NULL AS video_id, resource_url, resource_type, NULL AS data, NULL AS message FROM gamelog_resource_load WHERE resource_url LIKE @searchLike ${checkString} ${checkImage} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (selects.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const gamelogDatabase = [];
|
||||||
|
const args = {
|
||||||
|
'@searchLike': searchLike,
|
||||||
|
'@limit': maxEntries,
|
||||||
|
'@perTable': maxEntries,
|
||||||
|
...vipArgs
|
||||||
};
|
};
|
||||||
gamelogDatabase.sort(compareByCreatedAt);
|
await sqliteService.execute(
|
||||||
if (gamelogDatabase.length > maxEntries) {
|
(dbRow) => {
|
||||||
gamelogDatabase.splice(0, gamelogDatabase.length - maxEntries);
|
const type = dbRow[2];
|
||||||
|
const row = {
|
||||||
|
rowId: dbRow[0],
|
||||||
|
created_at: dbRow[1],
|
||||||
|
type
|
||||||
|
};
|
||||||
|
switch (type) {
|
||||||
|
case 'Location':
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.worldId = dbRow[7];
|
||||||
|
row.worldName = dbRow[8];
|
||||||
|
row.time = dbRow[6];
|
||||||
|
row.groupName = dbRow[9];
|
||||||
|
break;
|
||||||
|
case 'OnPlayerJoined':
|
||||||
|
case 'OnPlayerLeft':
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.time = dbRow[6];
|
||||||
|
break;
|
||||||
|
case 'PortalSpawn':
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.instanceId = dbRow[10];
|
||||||
|
row.worldName = dbRow[8];
|
||||||
|
break;
|
||||||
|
case 'VideoPlay':
|
||||||
|
row.videoUrl = dbRow[11];
|
||||||
|
row.videoName = dbRow[12];
|
||||||
|
row.videoId = dbRow[13];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
break;
|
||||||
|
case 'Event':
|
||||||
|
row.data = dbRow[16];
|
||||||
|
break;
|
||||||
|
case 'External':
|
||||||
|
row.message = dbRow[17];
|
||||||
|
row.displayName = dbRow[3];
|
||||||
|
row.userId = dbRow[5];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
break;
|
||||||
|
case 'StringLoad':
|
||||||
|
case 'ImageLoad':
|
||||||
|
row.resourceUrl = dbRow[14];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
gamelogDatabase.push(row);
|
||||||
|
},
|
||||||
|
`SELECT ${baseColumns} FROM (${selects.join(' UNION ALL ')}) ORDER BY created_at DESC, id DESC LIMIT @limit`,
|
||||||
|
args
|
||||||
|
);
|
||||||
return gamelogDatabase;
|
return gamelogDatabase;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+27
-23
@@ -1,4 +1,4 @@
|
|||||||
import { reactive, ref, shallowReactive, watch } from 'vue';
|
import { reactive, ref, shallowRef, watch } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { toast } from 'vue-sonner';
|
import { toast } from 'vue-sonner';
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
lastLocationAvatarList: new Map()
|
lastLocationAvatarList: new Map()
|
||||||
});
|
});
|
||||||
|
|
||||||
const gameLogTableData = shallowReactive([]);
|
const gameLogTableData = shallowRef([]);
|
||||||
const gameLogTable = ref({
|
const gameLogTable = ref({
|
||||||
loading: false,
|
loading: false,
|
||||||
search: '',
|
search: '',
|
||||||
@@ -88,7 +88,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
watch(
|
watch(
|
||||||
() => watchState.isLoggedIn,
|
() => watchState.isLoggedIn,
|
||||||
(isLoggedIn) => {
|
(isLoggedIn) => {
|
||||||
gameLogTableData.length = 0;
|
gameLogTableData.value = [];
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
// wait for friends to load, silly but works
|
// wait for friends to load, silly but works
|
||||||
workerTimers.setTimeout(() => {
|
workerTimers.setTimeout(() => {
|
||||||
@@ -165,25 +165,25 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
|
|
||||||
function insertGameLogSorted(entry) {
|
function insertGameLogSorted(entry) {
|
||||||
const data = gameLogTableData;
|
const data = gameLogTableData;
|
||||||
if (data.length === 0) {
|
if (data.value.length === 0) {
|
||||||
data.push(entry);
|
data.value.push(entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (compareGameLogRows(entry, data[0]) < 0) {
|
if (compareGameLogRows(entry, data.value[0]) < 0) {
|
||||||
data.unshift(entry);
|
data.value.unshift(entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (compareGameLogRows(entry, data[data.length - 1]) > 0) {
|
if (compareGameLogRows(entry, data[data.value.length - 1]) > 0) {
|
||||||
data.push(entry);
|
data.value.push(entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (let i = 1; i < data.length; i++) {
|
for (let i = 1; i < data.value.length; i++) {
|
||||||
if (compareGameLogRows(entry, data[i]) < 0) {
|
if (compareGameLogRows(entry, data[i]) < 0) {
|
||||||
data.splice(i, 0, entry);
|
data.value.splice(i, 0, entry);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.push(entry);
|
data.value.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearNowPlaying() {
|
function clearNowPlaying() {
|
||||||
@@ -392,19 +392,26 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
if (gameLogTable.value.vip) {
|
if (gameLogTable.value.vip) {
|
||||||
vipList = Array.from(friendStore.localFavoriteFriends.values());
|
vipList = Array.from(friendStore.localFavoriteFriends.values());
|
||||||
}
|
}
|
||||||
const rows = await database.lookupGameLogDatabase(
|
const search = gameLogTable.value.search.trim();
|
||||||
gameLogTable.value.search,
|
let rows = [];
|
||||||
|
if (search) {
|
||||||
|
rows = await database.searchGameLogDatabase(
|
||||||
|
search,
|
||||||
gameLogTable.value.filter,
|
gameLogTable.value.filter,
|
||||||
vipList
|
vipList
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
rows = await database.lookupGameLogDatabase(
|
||||||
|
gameLogTable.value.filter,
|
||||||
|
vipList
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
row.isFriend = gameLogIsFriend(row);
|
row.isFriend = gameLogIsFriend(row);
|
||||||
row.isFavorite = gameLogIsFavorite(row);
|
row.isFavorite = gameLogIsFavorite(row);
|
||||||
}
|
}
|
||||||
rows.sort(compareGameLogRows);
|
gameLogTableData.value = rows;
|
||||||
gameLogTableData.length = 0;
|
|
||||||
gameLogTableData.push(...rows);
|
|
||||||
gameLogTable.value.loading = false;
|
gameLogTable.value.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,9 +534,9 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sweepGameLog() {
|
function sweepGameLog() {
|
||||||
const j = gameLogTableData.length;
|
const j = gameLogTableData.value.length;
|
||||||
if (j > vrcxStore.maxTableSize + 50) {
|
if (j > vrcxStore.maxTableSize + 50) {
|
||||||
gameLogTableData.splice(-50, 50);
|
gameLogTableData.value.splice(-50, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1419,7 +1426,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
|
|
||||||
async function initGameLogTable() {
|
async function initGameLogTable() {
|
||||||
const rows = await database.lookupGameLogDatabase(
|
const rows = await database.lookupGameLogDatabase(
|
||||||
gameLogTable.value.search,
|
|
||||||
gameLogTable.value.filter,
|
gameLogTable.value.filter,
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -1427,9 +1433,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
|
|||||||
row.isFriend = gameLogIsFriend(row);
|
row.isFriend = gameLogIsFriend(row);
|
||||||
row.isFavorite = gameLogIsFavorite(row);
|
row.isFavorite = gameLogIsFavorite(row);
|
||||||
}
|
}
|
||||||
rows.sort(compareGameLogRows);
|
gameLogTableData.value = rows;
|
||||||
gameLogTableData.length = 0;
|
|
||||||
gameLogTableData.push(...rows);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ export const useLocationStore = defineStore('Location', () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const lastLocationArray = await database.lookupGameLogDatabase(
|
const lastLocationArray = await database.lookupGameLogDatabase(
|
||||||
'',
|
|
||||||
['Location'],
|
['Location'],
|
||||||
[],
|
[],
|
||||||
1
|
1
|
||||||
|
|||||||
@@ -878,6 +878,7 @@ export const useAppearanceSettingsStore = defineStore(
|
|||||||
.then(async ({ ok, value }) => {
|
.then(async ({ ok, value }) => {
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
if (value) {
|
if (value) {
|
||||||
|
// TODO
|
||||||
let processedValue = Number(value);
|
let processedValue = Number(value);
|
||||||
if (processedValue > 10000) {
|
if (processedValue > 10000) {
|
||||||
processedValue = 10000;
|
processedValue = 10000;
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
|
|||||||
// GameLog
|
// GameLog
|
||||||
if (vipFilters.length) {
|
if (vipFilters.length) {
|
||||||
const vipGameLogRows = await database.lookupGameLogDatabase(
|
const vipGameLogRows = await database.lookupGameLogDatabase(
|
||||||
'',
|
|
||||||
vipFilters,
|
vipFilters,
|
||||||
vipList,
|
vipList,
|
||||||
maxEntries
|
maxEntries
|
||||||
@@ -161,7 +160,6 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
|
|||||||
}
|
}
|
||||||
if (friendsFilters.length) {
|
if (friendsFilters.length) {
|
||||||
const friendsGameLogRows = await database.lookupGameLogDatabase(
|
const friendsGameLogRows = await database.lookupGameLogDatabase(
|
||||||
'',
|
|
||||||
friendsFilters,
|
friendsFilters,
|
||||||
friendList,
|
friendList,
|
||||||
maxEntries
|
maxEntries
|
||||||
@@ -170,7 +168,6 @@ export const useSharedFeedStore = defineStore('SharedFeed', () => {
|
|||||||
}
|
}
|
||||||
if (everyoneFilters.length) {
|
if (everyoneFilters.length) {
|
||||||
const everyoneGameLogRows = await database.lookupGameLogDatabase(
|
const everyoneGameLogRows = await database.lookupGameLogDatabase(
|
||||||
'',
|
|
||||||
everyoneFilters,
|
everyoneFilters,
|
||||||
[],
|
[],
|
||||||
maxEntries
|
maxEntries
|
||||||
|
|||||||
Reference in New Issue
Block a user