summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--schema.sql12
-rw-r--r--server.js24
2 files changed, 19 insertions, 17 deletions
diff --git a/schema.sql b/schema.sql
index f38ba53..04c613b 100644
--- a/schema.sql
+++ b/schema.sql
@@ -86,7 +86,7 @@ create view user_profile_view as
user_id, name, mail, notify, ctime, atime, about, is_banned
from
users
- natural left join user_last_seen
+ left join user_last_seen using(user_id)
;
drop view if exists user_dynamic_view;
@@ -179,7 +179,7 @@ create view rating_view as
title_id, name, rating, count, last
from
ratings
- natural join users
+ join users using(title_id, user_id)
order by
title_id,
rating desc
@@ -194,8 +194,8 @@ create view player_rating_view as
coalesce(rating, 1500) as rating,
coalesce(count, 0) as count
from players
- natural join games
- natural left join ratings
+ join games using(game_id)
+ left join ratings using(title_id, user_id)
;
-- Friend and Block Lists --
@@ -393,7 +393,7 @@ create view game_chat_view as
game_id, chat_id, time, name, message
from
game_chat
- natural join users
+ join users using(user_id)
;
create table if not exists game_replay (
@@ -439,7 +439,7 @@ create view game_view as
user_count = join_count and join_count > 1 as is_opposed
from
games
- natural join titles
+ join titles using(title_id)
join users as owner
on owner.user_id = games.owner_id
;
diff --git a/server.js b/server.js
index 137a24d..e9a8c1f 100644
--- a/server.js
+++ b/server.js
@@ -1194,7 +1194,7 @@ const SQL_SELECT_REPLAY = SQL(`
json_object('role', role, 'name', name)
)
from players
- natural join users
+ join users using(user_id)
where game_id = :game_id
),
'state',
@@ -2729,48 +2729,49 @@ app.get('/stats', function (req, res) {
const SQL_USER_STATS = SQL(`
select
- title_name,
+ titles.title_name,
scenario,
role,
sum(role=result) as won,
count(*) as total
from
players
- natural join game_view
- natural join titles
+ join game_view using(game_id)
+ join titles using(title_id)
where
not is_symmetric
and user_id = ?
and is_opposed
and ( status = ${STATUS_FINISHED} or status = ${STATUS_ARCHIVED} )
group by
- title_name,
+ titles.title_name,
scenario,
role
union
select
- title_name,
+ titles.title_name,
scenario,
null as role,
sum(role=result) as won,
count(*) as total
from
players
- natural join game_view
- natural join titles
+ join game_view using(game_id)
+ join titles using(title_id)
where
is_symmetric
and user_id = ?
and is_opposed
and ( status = ${STATUS_FINISHED} or status = ${STATUS_ARCHIVED} )
group by
- title_name,
+ titles.title_name,
scenario
`)
const SQL_USER_RATINGS = SQL(`
select title_name, rating, count, date(last) as last
- from ratings natural join titles
+ from ratings
+ join titles using(title_id)
where user_id = ?
and count >= 5
order by rating desc
@@ -2778,7 +2779,8 @@ const SQL_USER_RATINGS = SQL(`
const SQL_GAME_RATINGS = SQL(`
select name, rating, count, date(last) as last
- from ratings natural join users
+ from ratings
+ join users using(user_id)
where title_id = ? and rating >= 1600 and count >= 10
order by rating desc
limit 50