From 148674065bedcd1d9557b5c0becd490e7e118339 Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 21 Feb 2024 20:50:02 +0300 Subject: [PATCH] jdbc migrate clean up fix --- .../java/app/services/ProfileService.java | 108 ++++++++++++------ .../java/app/services/db/KillfeedService.java | 28 ++--- .../java/app/services/db/UsertimeService.java | 7 +- 3 files changed, 94 insertions(+), 49 deletions(-) diff --git a/src/main/java/app/services/ProfileService.java b/src/main/java/app/services/ProfileService.java index 961c9fd..7374e3f 100644 --- a/src/main/java/app/services/ProfileService.java +++ b/src/main/java/app/services/ProfileService.java @@ -80,96 +80,133 @@ public class ProfileService { callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setPlay_on(statsService.searchPlayer(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("play_on", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setPlay_on(statsService.searchPlayer(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("play_on", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); if(requests.contains("steam_data")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("steam_data", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setSteam_data(steamWebApi.getSteamData(steamID.steam64)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("steam_data", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } if(requests.contains("lastplay")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setLastplay(usertimeService.getPlayerLastplay(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("lastplay", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setLastplay(usertimeService.getPlayerLastplay(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("lastplay", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } if(requests.contains("usertime")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setGametime(usertimeService.getPlayerUsertime(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("usertime", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setGametime(usertimeService.getPlayerUsertime(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("usertime", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } //if(requests.contains("permition")){ callables.add(() -> { + try { long start_time = Instant.now().toEpochMilli(); profile.setPermition(permitionService.getPermition(steamID)); long end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("permition", (double) end_time / 1000); - return null; + } catch (Exception err) { + err.printStackTrace(); + } + return null; }); //} //if(requests.contains("ban")){ callables.add(() -> { + try { long start_time = Instant.now().toEpochMilli(); profile.setBan(banService.getBan(steamID)); long end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("ban", (double) end_time / 1000); - return null; - }); + } catch (Exception err) { + err.printStackTrace(); + } + return null; + }); //} if(requests.contains("attached_discord")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("attached_discord", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setAttached_discords(detectService.getAttachedDiscordAccountPerSteam(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("attached_discord", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } if(requests.contains("donates")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setDonates(donateService.getDonateStatistic(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("donates", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setDonates(donateService.getDonateStatistic(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("donates", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } if(requests.contains("ban_list")){ callables.add(() -> { - long start_time = Instant.now().toEpochMilli(); - profile.setBan_list(banService.getBans(steamID)); - long end_time = Instant.now().toEpochMilli() - start_time; - profile.getResponse_time().put("ban_list", (double) end_time / 1000); + try { + long start_time = Instant.now().toEpochMilli(); + profile.setBan_list(banService.getBans(steamID)); + long end_time = Instant.now().toEpochMilli() - start_time; + profile.getResponse_time().put("ban_list", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); } //if(requests.contains("killfeed")){ callables.add(() -> { + try { long start_time = Instant.now().toEpochMilli(); profile.setKillfeed((new Killfeed()) .setKills(killfeedService.getKills(steamID, null)) @@ -178,16 +215,23 @@ public class ProfileService { .setSuicides(killfeedService.getSuicides(steamID, null))); long end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("killfeed", (double) end_time / 1000); - return null; + } catch (Exception err) { + err.printStackTrace(); + } + return null; }); //} //if(requests.contains("messages")){ callables.add(() -> { + try { long start_time = Instant.now().toEpochMilli(); profile.setMessages(messageService.getMessageCount(steamID, null)); long end_time = Instant.now().toEpochMilli() - start_time; profile.getResponse_time().put("messages", (double) end_time / 1000); + } catch (Exception err) { + err.printStackTrace(); + } return null; }); //} diff --git a/src/main/java/app/services/db/KillfeedService.java b/src/main/java/app/services/db/KillfeedService.java index 092d596..bce73c7 100644 --- a/src/main/java/app/services/db/KillfeedService.java +++ b/src/main/java/app/services/db/KillfeedService.java @@ -31,63 +31,63 @@ public class KillfeedService { public Long getKills(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); } public List getTopKills(String server_id) { return jdbcTemplate.query("SELECT `attacker_id`, count(*) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `attacker_id` != 0 AND `server_id` LIKE ? GROUP BY `attacker_id` ORDER BY `c` DESC LIMIT 10", - new Object[]{server_id == null || server_id.isEmpty() ? '%' : server_id}, + new Object[]{server_id == null || server_id.isEmpty() ? "%" : server_id}, (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); } public Long getDeads(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); } public List getTopDeads(String server_id) { return jdbcTemplate.query("SELECT `victim_id`, count(`id`) as c, `server_id` FROM `user_killfeed` WHERE `victim_id` != `attacker_id` AND `victim_id` != 0 AND `server_id` LIKE ? GROUP BY `victim_id` ORDER BY `c` DESC LIMIT 10", - new Object[]{ server_id == null || server_id.isEmpty() ? '%' : server_id}, + new Object[]{ server_id == null || server_id.isEmpty() ? "%" : server_id}, (rs, n) -> new TopInFeed(rs).setNicknames(nicknameService)); } public Long getSuicides(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` = `victim_id` AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); } public Long getAssists(SteamID steamID, String server_id) { return jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id}, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id}, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); } public Map getPopulateWeapons(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT COUNT(u.`weapon_index`) as c, i.`name`, u.`server_id`, u.`weapon_classname` FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ? AND `attacker_id` != `victim_id` AND u.server_id like ? GROUP BY u.`weapon_index` DESC ORDER BY `c` DESC LIMIT ? OFFSET ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id, limit, offset }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id, limit, offset }, (rs, n) -> new HypeWeapons(rs)); /*Long count = (Long) createNativeQuery("SELECT COUNT(`weapon_index`) FROM `user_killfeed` WHERE `attacker_id` = ? AND server_id like ? GROUP BY `weapon_index`") .setParameter(1, steamID.account_id) - .setParameter(2, server_id==null||server_id.isEmpty()?'%':server_id) + .setParameter(2, server_id==null||server_id.isEmpty()?"%":server_id) .getSingleResult();*/ return Map.of("result", result, "count", -1); } public Map getKills(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT -1, u.victim_id, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`attacker_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", - new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, + new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `attacker_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); @@ -96,11 +96,11 @@ public class KillfeedService { public Map getDeads(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT u.attacker_id, -1, u.assister_id, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`victim_id` = ? AND u.`attacker_id` != u.`victim_id` AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", - new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, + new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `victim_id` = ? AND `attacker_id` != `victim_id` AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L); return Map.of("result", result, "count", count, "type", FeedType.DEAD.ordinal()); @@ -108,11 +108,11 @@ public class KillfeedService { public Map getAssists(SteamID steamID, String server_id, int offset, int limit) { List result = jdbcTemplate.query("SELECT u.attacker_id, u.victim_id, -1, u.utime, i.name, u.server_id, u.weapon_classname FROM `user_killfeed` as u INNER JOIN `tf2idb`.`tf2idb_item` as i ON u.`weapon_index` = i.`id` WHERE u.`assister_id` = ? AND u.`server_id` like ? ORDER BY u.`id` DESC LIMIT ? OFFSET ?", - new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? '%' : server_id, limit, offset}, + new Object[]{steamID.account_id, server_id == null || server_id.isEmpty() ? "%" : server_id, limit, offset}, (rs, n) -> new KillsInFeed(rs).setNicknames(nicknameService)); Long count = jdbcTemplate.query("SELECT COUNT(*) as c FROM `user_killfeed` WHERE `assister_id` = ? AND `server_id` like ?", - new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?'%':server_id }, + new Object[]{ steamID.account_id, server_id==null||server_id.isEmpty()?"%":server_id }, (rs, n) -> rs.getLong("c")) .stream().findFirst().orElse(0L); diff --git a/src/main/java/app/services/db/UsertimeService.java b/src/main/java/app/services/db/UsertimeService.java index 04cd557..d06e505 100644 --- a/src/main/java/app/services/db/UsertimeService.java +++ b/src/main/java/app/services/db/UsertimeService.java @@ -93,10 +93,11 @@ public class UsertimeService { } public BigDecimal getTotalPlaytime(String db, SteamID steamID, String map) { - return jdbcTemplate.query("select sum(connect_duration) as total from `"+db+"`.`user_connections` WHERE map LIKE ? and connection_type LIKE ? AND account_id = ?", + List l = jdbcTemplate.query("select sum(connect_duration) as total from `"+db+"`.`user_connections` WHERE map LIKE ? and connection_type LIKE ? AND account_id = ?", new Object[]{ map, "disconnect", steamID.account_id }, - (rs, n) -> rs.getBigDecimal("total")) - .stream().findFirst().orElse(null); + (rs, n) -> rs.getBigDecimal("total")); + //optional if has error + return l.size() > 0?l.get(0):null; } public List getMap(String db, int limit) {