Browse Source

rewrite shits / fix

master
gsd 4 days ago
parent
commit
ae21df1e8e
  1. 52
      src/main/java/app/services/db/KillfeedService.java
  2. 20
      src/main/java/app/services/db/MessageService.java
  3. 20
      src/main/java/app/updates/OnlineUpdater.java

52
src/main/java/app/services/db/KillfeedService.java

@ -37,11 +37,11 @@ public class KillfeedService {
public Long getKills(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND attacker_id = ? AND attacker_id != victim_id AND (? is null or server_id like ?)",
"WHERE utime > ? AND attacker_id = ? AND attacker_id != victim_id AND (? = 0 or server_id like ?)",
new Object[]{
utime==null?0:utime,
steamID.account_id,
server_id==null||server_id.isEmpty()?null:server_id,
server_id==null||server_id.isEmpty()?0:1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -50,11 +50,11 @@ public class KillfeedService {
public List<TopInFeed> 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 (? is null or server_id LIKE ?) " +
"WHERE victim_id != attacker_id AND attacker_id != 0 AND (? =0 or server_id LIKE ?) " +
"GROUP BY attacker_id, server_id " +
"ORDER BY c DESC LIMIT 10",
new Object[]{
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id},
(rs, n) -> new TopInFeed(rs).setNicknames(nicknameService));
}
@ -62,11 +62,11 @@ public class KillfeedService {
public Long getDeads(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND victim_id = ? AND attacker_id != victim_id AND (? is null or server_id like ?)",
"WHERE utime > ? AND victim_id = ? AND attacker_id != victim_id AND (? =0 or server_id like ?)",
new Object[]{
utime==null?0:utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -75,11 +75,11 @@ public class KillfeedService {
public List<TopInFeed> 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 (? is null or server_id LIKE ?) " +
"WHERE victim_id != attacker_id AND victim_id != 0 AND (? =0 or server_id LIKE ?) " +
"GROUP BY victim_id, server_id " +
"ORDER BY c DESC LIMIT 10",
new Object[]{
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id},
(rs, n) -> new TopInFeed(rs).setNicknames(nicknameService));
}
@ -87,11 +87,11 @@ public class KillfeedService {
public Long getSuicides(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND victim_id = ? AND attacker_id = victim_id AND (? is null or server_id like ?)",
"WHERE utime > ? AND victim_id = ? AND attacker_id = victim_id AND (? =0 or server_id like ?)",
new Object[]{
utime==null?0:utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -100,11 +100,11 @@ public class KillfeedService {
public Long getAssists(SteamID steamID, String server_id, Long utime) {
return jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND assister_id = ? AND (? is null or server_id like ?)",
"WHERE utime > ? AND assister_id = ? AND (? =0 or server_id like ?)",
new Object[]{
utime==null?0:utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id},
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -114,12 +114,12 @@ public class KillfeedService {
List<HypeWeapons> 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 (? is null or u.server_id like ?) " +
"WHERE u.attacker_id = ? AND attacker_id != victim_id AND (? =0 or u.server_id like ?) " +
"GROUP BY u.weapon_index, i.name, u.server_id, u.weapon_classname " +
"ORDER BY c DESC LIMIT ? OFFSET ?",
new Object[]{
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id,
limit,
offset },
@ -143,12 +143,12 @@ public class KillfeedService {
List<KillsInFeed> 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.utime > ? AND u.attacker_id = ? AND u.attacker_id != u.victim_id AND (? is null or u.server_id like ?) " +
"WHERE u.utime > ? AND u.attacker_id = ? AND u.attacker_id != u.victim_id AND (? =0 or u.server_id like ?) " +
"ORDER BY u.id DESC LIMIT ? OFFSET ?",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id,
limit,
offset},
@ -156,11 +156,11 @@ public class KillfeedService {
Long count = jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND attacker_id = ? AND attacker_id != victim_id AND (? is null or server_id like ?)",
"WHERE utime > ? AND attacker_id = ? AND attacker_id != victim_id AND (? =0 or server_id like ?)",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);
@ -179,12 +179,12 @@ public class KillfeedService {
List<KillsInFeed> 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.utime > ? AND u.victim_id = ? AND u.attacker_id != u.victim_id AND (? is null or u.server_id like ?) " +
"WHERE u.utime > ? AND u.victim_id = ? AND u.attacker_id != u.victim_id AND (? =0 or u.server_id like ?) " +
"ORDER BY u.id DESC LIMIT ? OFFSET ?",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id,
limit,
offset},
@ -192,11 +192,11 @@ public class KillfeedService {
Long count = jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND victim_id = ? AND attacker_id != victim_id AND (? is null or server_id like ?)",
"WHERE utime > ? AND victim_id = ? AND attacker_id != victim_id AND (? =0 or server_id like ?)",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L);
@ -214,12 +214,12 @@ public class KillfeedService {
List<KillsInFeed> 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.utime > ? AND u.assister_id = ? AND (? is null or u.server_id like ?) " +
"WHERE u.utime > ? AND u.assister_id = ? AND (? =0 or u.server_id like ?) " +
"ORDER BY u.id DESC LIMIT ? OFFSET ?",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id,
limit,
offset},
@ -227,11 +227,11 @@ public class KillfeedService {
Long count = jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_killfeed " +
"WHERE utime > ? AND assister_id = ? AND (? is null or server_id like ?)",
"WHERE utime > ? AND assister_id = ? AND (? =0 or server_id like ?)",
new Object[]{
current_utime,
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);

20
src/main/java/app/services/db/MessageService.java

@ -34,10 +34,10 @@ public class MessageService {
public Map getAllMessages(String server_id, String filter, long offset, int limit) {
List<Message> result = jdbcTemplate.query("SELECT account_id,utime,message,server_id " +
"FROM user_messages " +
"WHERE (? is null or server_id like ?) AND message LIKE ? " +
"WHERE (? =0 or server_id like ?) AND message LIKE ? " +
"ORDER BY user_messages.id DESC LIMIT ? OFFSET ?",
new Object[]{
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id,
filter == null || filter.isEmpty() ? "%" : "%" + filter + "%",
limit,
@ -46,9 +46,9 @@ public class MessageService {
Long count = jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_messages " +
"WHERE (? is null or server_id like ?) AND message LIKE ?",
"WHERE (? =0 or server_id like ?) AND message LIKE ?",
new Object[]{
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id,
filter==null||filter.isEmpty()?"%":"%" + filter + "%" },
(rs, n) -> rs.getLong("c"))
@ -60,11 +60,11 @@ public class MessageService {
public Map getAccountMessages(SteamID steamID, String server_id, String filter, int offset, int limit) {
List<Message> result = jdbcTemplate.query("SELECT account_id,utime,message,server_id " +
"FROM user_messages " +
"WHERE account_id = ? AND (? is null or server_id like ?) AND message LIKE ? " +
"WHERE account_id = ? AND (? =0 or server_id like ?) AND message LIKE ? " +
"ORDER BY user_messages.id DESC LIMIT ? OFFSET ?",
new Object[]{
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id == null || server_id.isEmpty() ? "%" : server_id,
filter == null || filter.isEmpty() ? "%" : "%" + filter + "%",
limit,
@ -73,10 +73,10 @@ public class MessageService {
Long count = jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_messages " +
"WHERE account_id = ? AND (? is null or server_id like ?) AND message LIKE ?",
"WHERE account_id = ? AND (? =0 or server_id like ?) AND message LIKE ?",
new Object[]{
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id,
filter==null||filter.isEmpty()?"%":"%" + filter + "%"},
(rs, n) -> rs.getLong("c"))
@ -88,10 +88,10 @@ public class MessageService {
public Long getMessageCount(SteamID steamID, String server_id) {
return jdbcTemplate.query("SELECT COUNT(*) as c " +
"FROM user_messages " +
"WHERE account_id = ? AND (? is null or server_id like ?)",
"WHERE account_id = ? AND (? =0 or server_id like ?)",
new Object[]{
steamID.account_id,
server_id == null || server_id.isEmpty() ? null : server_id,
server_id == null || server_id.isEmpty() ? 0 : 1,
server_id==null||server_id.isEmpty()?"%":server_id },
(rs, n) -> rs.getLong("c"))
.stream().findFirst().orElse(0L);

20
src/main/java/app/updates/OnlineUpdater.java

@ -68,10 +68,10 @@ public class OnlineUpdater extends BaseUpdater {
//todo abstract on all
public List<PerDayStats> getStatsOnPerDay(String server_id) {
return jdbcTemplate_ro.query("SELECT avg(player_count) as player_count, cast(to_timestamp(utime) as date) as fulldate, utime as ts " +
"FROM servers_online WHERE player_count != 0 and (? is null or server_id like ?) " +
"FROM servers_online WHERE player_count != 0 and (? =0 or server_id like ?) " +
"GROUP BY cast(to_timestamp(utime) as date) / ? ORDER BY ts ASC",
new Object[]{
server_id == null || server_id.isEmpty() ? null: server_id,
server_id == null || server_id.isEmpty() ? 0: 1,
server_id == null || server_id.isEmpty() ? "%": server_id,
PerDayStats.period},
(rs, rowNum) -> new PerDayStats(rs));
@ -79,10 +79,10 @@ public class OnlineUpdater extends BaseUpdater {
public List<PerFiveMinutesStats> getStatsOnPerFiveMinutes(String server_id) {
return jdbcTemplate_ro.query("SELECT avg(player_count) as player_count, cast(to_timestamp(utime) as date) as fulldate, utime as ts " +
"FROM servers_online WHERE player_count != 0 and (? is null or server_id like ?) " +
"FROM servers_online WHERE player_count != 0 and (? =0 or server_id like ?) " +
"GROUP BY cast(to_timestamp(utime) as date) / ? ORDER BY ts ASC",
new Object[]{
server_id == null || server_id.isEmpty() ? null: server_id,
server_id == null || server_id.isEmpty() ? 0: 1,
server_id == null || server_id.isEmpty() ? "%": server_id,
PerFiveMinutesStats.period},
(rs, rowNum) -> new PerFiveMinutesStats(rs));
@ -104,11 +104,11 @@ public class OnlineUpdater extends BaseUpdater {
SELECT round(sum(s.player_count))::int as player_count, s.ts as fl FROM (
SELECT round(max(player_count), 4) as player_count, to_timestamp(utime)::date as ts
FROM servers_online
WHERE (? is null or server_id like ?) and player_count != 0
WHERE (? = 0 or server_id like ?) and player_count != 0
GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
""",
new Object[]{
server_id==null||server_id.isEmpty()?null:server_id,
server_id==null||server_id.isEmpty()?0:1,
server_id==null||server_id.isEmpty()?"%":server_id,
limit},
(rs, rowNum) -> new MaxPeakOfDay(rs));
@ -119,11 +119,11 @@ GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
SELECT round(sum(s.player_count))::int as player_count, s.ts as fl FROM (
SELECT round(avg(player_count), 4) as player_count, to_timestamp(utime)::date as ts
FROM servers_online
WHERE (? is null or server_id like ?) and player_count != 0
WHERE (? = 0 or server_id like ?) and player_count != 0
GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
""",
new Object[]{
server_id==null||server_id.isEmpty()?null:server_id,
server_id==null||server_id.isEmpty()?0:1,
server_id==null||server_id.isEmpty()?"%":server_id,
limit},
(rs, rowNum) -> new AvgPeakOfDay(rs));
@ -134,11 +134,11 @@ GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
return jdbcTemplate_ro.query("select round(sum(sub.player_count))::int as player_count, sub.ts as fulldate from ("+
"SELECT round(avg(player_count), 4) as player_count, date_bin('"+minutes+" minutes'"+",to_timestamp(utime)::timestamp, '2001-01-01 00:02:30') as ts "+
"FROM servers_online " +
"WHERE utime >= ? and (? is null or server_id like ?) "+
"WHERE utime >= ? and (? = 0 or server_id like ?) "+
"GROUP BY ts, server_id) sub GROUP BY sub.ts ",
new Object[]{
utime,
server_id==null||server_id.isEmpty()?null:server_id,
server_id==null||server_id.isEmpty()?0:1,
server_id==null||server_id.isEmpty()?"%":server_id},
(rs, rowNum) -> new StatsOfPeakOfPerFiveMinutes(rs));
}

Loading…
Cancel
Save