Add GameLog entries for resource loading (#513)

* add log entries for resource loading

* add config for resource loading
This commit is contained in:
BoatFloater
2023-03-24 23:57:55 +09:00
committed by GitHub
parent 11f1f8063e
commit 3f0a479e1a
9 changed files with 151 additions and 2 deletions

View File

@@ -56,6 +56,9 @@ class Database {
await sqliteService.executeNonQuery(
`CREATE TABLE IF NOT EXISTS gamelog_video_play (id INTEGER PRIMARY KEY, created_at TEXT, video_url TEXT, video_name TEXT, video_id TEXT, location TEXT, display_name TEXT, user_id TEXT, UNIQUE(created_at, video_url))`
);
await sqliteService.executeNonQuery(
`CREATE TABLE IF NOT EXISTS gamelog_resource_load (id INTEGER PRIMARY KEY, created_at TEXT, resource_url TEXT, resource_type TEXT, location TEXT, UNIQUE(created_at, resource_url))`
);
await sqliteService.executeNonQuery(
`CREATE TABLE IF NOT EXISTS gamelog_event (id INTEGER PRIMARY KEY, created_at TEXT, data TEXT, UNIQUE(created_at, data))`
);
@@ -498,6 +501,17 @@ class Database {
};
gamelogDatabase.unshift(row);
}, `SELECT * FROM gamelog_video_play WHERE created_at >= date('${dateOffset}') ORDER BY id DESC`);
await sqliteService.execute((dbRow) => {
var row = {
rowId: dbRow[0],
created_at: dbRow[1],
type: dbRow[3] === 'string' ? 'StringLoad' : 'ImageLoad',
resourceUrl: dbRow[2],
resourceType: dbRow[3],
location: dbRow[4]
};
gamelogDatabase.unshift(row);
}, `SELECT * FROM gamelog_resource_load WHERE created_at >= date('${dateOffset}') ORDER BY id DESC`);
await sqliteService.execute((dbRow) => {
var row = {
rowId: dbRow[0],
@@ -621,6 +635,18 @@ class Database {
);
}
addGamelogResourceLoadToDatabase(entry) {
sqliteService.executeNonQuery(
`INSERT OR IGNORE INTO gamelog_resource_load (created_at, resource_url, resource_type, location) VALUES (@created_at, @resource_url, @resource_type, @location)`,
{
'@created_at': entry.created_at,
'@resource_url': entry.resourceUrl,
'@resource_type': entry.resourceType,
'@location': entry.location
}
);
}
addGamelogEventToDatabase(entry) {
sqliteService.executeNonQuery(
`INSERT OR IGNORE INTO gamelog_event (created_at, data) VALUES (@created_at, @data)`,
@@ -816,6 +842,14 @@ class Database {
return size;
}
async getResourceLoadTableSize() {
var size = 0;
await sqliteService.execute((row) => {
size = row[0];
}, `SELECT COUNT(*) FROM gamelog_resource_load`);
return size;
}
async getEventTableSize() {
var size = 0;
await sqliteService.execute((row) => {
@@ -1176,6 +1210,8 @@ class Database {
var portalspawn = true;
var msgevent = true;
var videoplay = true;
var resourceload_string = true;
var resourceload_image = true;
if (filters.length > 0) {
location = false;
onplayerjoined = false;
@@ -1183,6 +1219,8 @@ class Database {
portalspawn = false;
msgevent = false;
videoplay = false;
resourceload_string = false;
resourceload_image = false;
filters.forEach((filter) => {
switch (filter) {
case 'Location':
@@ -1203,6 +1241,12 @@ class Database {
case 'VideoPlay':
videoplay = true;
break;
case 'StringLoad':
resourceload_string = true;
break;
case 'ImageLoad':
resourceload_image = true;
break;
}
});
}
@@ -1286,6 +1330,27 @@ class Database {
gamelogDatabase.unshift(row);
}, `SELECT * FROM gamelog_video_play WHERE video_url LIKE '%${search}%' OR video_name LIKE '%${search}%' OR display_name LIKE '%${search}%' ORDER BY id DESC LIMIT ${Database.maxTableSize}`);
}
if (resourceload_string || resourceload_image) {
var checkString = '';
var checkImage = '';
if (!resourceload_string) {
checkString = `AND resource_type != 'string'`;
}
if (!resourceload_image) {
checkString = `AND resource_type != 'image'`;
}
await sqliteService.execute((dbRow) => {
var row = {
rowId: dbRow[0],
created_at: dbRow[1],
type: dbRow[3] === 'string' ? 'StringLoad' : 'ImageLoad',
resourceUrl: dbRow[2],
resourceType: dbRow[3],
location: dbRow[4]
};
gamelogDatabase.unshift(row);
}, `SELECT * FROM gamelog_resource_load WHERE resource_url LIKE '%${search}%' ${checkString} ${checkImage} ORDER BY id DESC LIMIT ${Database.maxTableSize}`);
}
var compareByCreatedAt = function (a, b) {
var A = a.created_at;
var B = b.created_at;
@@ -1324,6 +1389,9 @@ class Database {
await sqliteService.execute((dbRow) => {
gamelogDatabase.unshift(dbRow[0]);
}, 'SELECT created_at FROM gamelog_video_play ORDER BY id DESC LIMIT 1');
await sqliteService.execute((dbRow) => {
gamelogDatabase.unshift(dbRow[0]);
}, 'SELECT created_at FROM gamelog_resource_load ORDER BY id DESC LIMIT 1');
if (gamelogDatabase.length > 0) {
gamelogDatabase.sort();
var newDate = gamelogDatabase[gamelogDatabase.length - 1];