UPDATE
lol_queue
SET
- position = position + 1
+ position = (
+ CASE
+ WHEN (
+ SELECT
+ position
+ FROM
+ lol_queue
+ WHERE
+ twitch_id = ?
+ ) < (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ THEN position + 1
+ ELSE position
+ END
+ )
WHERE
- position >= (
+ position > (
SELECT
- data
- FROM
- lol_queue_data
+ max(position)
+ FROM
+ lol_queue
WHERE
- name = 'queuesize'
- )
+ priority_queue = 1
+ OR position <= (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ );
"""
)
lol_queue
SET
available = 1,
- position = (
+ priority_queue = (
+ CASE
+ WHEN (
+ SELECT
+ position
+ FROM
+ lol_queue
+ WHERE
+ twitch_id = ?
+ ) < (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ THEN 1
+ ELSE 0
+ END
+ ),
+ position = 1 + (
SELECT
- data
+ max(position)
FROM
- lol_queue_data
+ lol_queue
WHERE
- name = 'queuesize'
- ),
+ priority_queue = 1
+ OR position <= (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ )
time_remaining = time_remaining - (? - last_available)
WHERE
twitch_id = ?
UPDATE
lol_queue
SET
- position = position + 1
+ position = (
+ CASE
+ WHEN (
+ SELECT
+ position
+ FROM
+ lol_queue
+ WHERE
+ twitch_id = ?
+ ) < (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ THEN position + 1
+ ELSE position
+ END
+ )
WHERE
- position >= (
+ position > (
SELECT
- data
- FROM
- lol_queue_data
+ max(position)
+ FROM
+ lol_queue
WHERE
- name = 'queuesize'
- )
+ priority_queue = 1
+ OR position <= (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ );
"""
)
lol_queue
SET
available = 1,
- position = (
+ priority_queue = (
+ CASE
+ WHEN (
+ SELECT
+ position
+ FROM
+ lol_queue
+ WHERE
+ twitch_id = ?
+ ) < (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ THEN 1
+ ELSE 0
+ END
+ ),
+ position = 1 + (
SELECT
- data
+ max(position)
FROM
- lol_queue_data
+ lol_queue
WHERE
- name = 'queuesize'
- ),
+ priority_queue = 1
+ OR position <= (
+ SELECT
+ max(position)
+ FROM
+ lol_queue
+ WHERE
+ available = 1
+ ORDER BY
+ position
+ LIMIT (
+ SELECT
+ data
+ FROM
+ lol_queue_data
+ WHERE
+ name = 'queuesize'
+ )
+ )
+ )
time_remaining = time_remaining - (? - last_available)
WHERE
twitch_id = ?
c.execute(
"""
- UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?;
+ UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?;
""",
(
int(time.time()),
c.execute(
"""
- UPDATE lol_queue SET available = 0, last_available = ? WHERE twitch_id = ?;
+ UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?;
""",
(
int(time.time()),
last_available INTEGER,
time_remaining INTEGER NOT NULL,
team INTEGER,
+ priority_queue INTEGER,
PRIMARY KEY (twitch_id)
);
"""