mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-30 12:13:48 +02:00
improve getGameLogByLocation sql
This commit is contained in:
@@ -516,15 +516,25 @@ const gameLog = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async getGameLogByLocation(instanceId, filters) {
|
async getGameLogByLocation(instanceId, filters, vipList = []) {
|
||||||
var gamelogDatabase = [];
|
let vipQuery = '';
|
||||||
var location = true;
|
const vipArgs = {};
|
||||||
var onplayerjoined = true;
|
if (vipList.length > 0) {
|
||||||
var onplayerleft = true;
|
const vipPlaceholders = [];
|
||||||
var portalspawn = true;
|
vipList.forEach((vip, i) => {
|
||||||
var videoplay = true;
|
const key = `@vip_${i}`;
|
||||||
var resourceload_string = true;
|
vipArgs[key] = vip;
|
||||||
var resourceload_image = true;
|
vipPlaceholders.push(key);
|
||||||
|
});
|
||||||
|
vipQuery = `AND user_id IN (${vipPlaceholders.join(', ')})`;
|
||||||
|
}
|
||||||
|
let location = true;
|
||||||
|
let onplayerjoined = true;
|
||||||
|
let onplayerleft = true;
|
||||||
|
let portalspawn = true;
|
||||||
|
let videoplay = true;
|
||||||
|
let resourceload_string = true;
|
||||||
|
let resourceload_image = true;
|
||||||
if (filters.length > 0) {
|
if (filters.length > 0) {
|
||||||
location = false;
|
location = false;
|
||||||
onplayerjoined = false;
|
onplayerjoined = false;
|
||||||
@@ -559,23 +569,34 @@ const gameLog = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
].join(', ');
|
||||||
|
|
||||||
|
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 FROM gamelog_location WHERE location LIKE @locationLike 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 location LIKE '%${instanceId}%' ORDER BY id DESC LIMIT ${dbVars.searchTableSize}`);
|
|
||||||
}
|
}
|
||||||
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'";
|
||||||
@@ -583,85 +604,93 @@ 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 FROM gamelog_join_leave WHERE (location LIKE @locationLike AND user_id != '${dbVars.userId}') ${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 (location LIKE '%${instanceId}%' AND user_id != '${dbVars.userId}') ${query} ORDER BY id DESC LIMIT ${dbVars.searchTableSize}`);
|
|
||||||
}
|
}
|
||||||
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 FROM gamelog_portal_spawn WHERE location LIKE @locationLike ${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 location LIKE '%${instanceId}%' ORDER BY id DESC LIMIT ${dbVars.searchTableSize}`);
|
|
||||||
}
|
}
|
||||||
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 FROM gamelog_video_play WHERE location LIKE @locationLike ${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 location LIKE '%${instanceId}%' ORDER BY id DESC LIMIT ${dbVars.searchTableSize}`);
|
|
||||||
}
|
}
|
||||||
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'`;
|
checkImage = `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 FROM gamelog_resource_load WHERE location LIKE @locationLike ${checkString} ${checkImage} ORDER BY id DESC LIMIT @perTable)`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selects.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const gamelogDatabase = [];
|
||||||
|
const args = {
|
||||||
|
'@locationLike': `%${instanceId}%`,
|
||||||
|
'@limit': dbVars.searchTableSize,
|
||||||
|
'@perTable': dbVars.searchTableSize,
|
||||||
|
...vipArgs
|
||||||
|
};
|
||||||
|
await sqliteService.execute(
|
||||||
|
(dbRow) => {
|
||||||
|
const type = dbRow[2];
|
||||||
|
const row = {
|
||||||
rowId: dbRow[0],
|
rowId: dbRow[0],
|
||||||
created_at: dbRow[1],
|
created_at: dbRow[1],
|
||||||
type: dbRow[3],
|
type
|
||||||
resourceUrl: dbRow[2],
|
|
||||||
location: dbRow[4]
|
|
||||||
};
|
};
|
||||||
|
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 'StringLoad':
|
||||||
|
case 'ImageLoad':
|
||||||
|
row.resourceUrl = dbRow[14];
|
||||||
|
row.location = dbRow[4];
|
||||||
|
break;
|
||||||
|
}
|
||||||
gamelogDatabase.push(row);
|
gamelogDatabase.push(row);
|
||||||
}, `SELECT * FROM gamelog_resource_load WHERE location LIKE '%${instanceId}%' ${checkString} ${checkImage} ORDER BY id DESC LIMIT ${dbVars.searchTableSize}`);
|
},
|
||||||
}
|
`SELECT ${baseColumns} FROM (${selects.join(' UNION ALL ')}) ORDER BY created_at DESC, id DESC LIMIT @limit`,
|
||||||
var compareByCreatedAt = function (a, b) {
|
args
|
||||||
var A = a.created_at;
|
|
||||||
var B = b.created_at;
|
|
||||||
if (A < B) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (A > B) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
gamelogDatabase.sort(compareByCreatedAt);
|
|
||||||
gamelogDatabase.splice(
|
|
||||||
0,
|
|
||||||
gamelogDatabase.length - dbVars.searchTableSize
|
|
||||||
);
|
);
|
||||||
return gamelogDatabase;
|
return gamelogDatabase;
|
||||||
},
|
},
|
||||||
@@ -888,7 +917,7 @@ const gameLog = {
|
|||||||
maxEntries = dbVars.searchTableSize
|
maxEntries = dbVars.searchTableSize
|
||||||
) {
|
) {
|
||||||
if (search.startsWith('wrld_') || search.startsWith('grp_')) {
|
if (search.startsWith('wrld_') || search.startsWith('grp_')) {
|
||||||
return this.getGameLogByLocation(search, filters);
|
return this.getGameLogByLocation(search, filters, vipList);
|
||||||
}
|
}
|
||||||
let vipQuery = '';
|
let vipQuery = '';
|
||||||
const vipArgs = {};
|
const vipArgs = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user