A further fix to the free slot algorithm

templates/content-index.tpl.html: the `TT²` algorithm can be simplified
    because the new query returns less. We get the date of the show
    before the free slot, and can increment it differently depending on
    whether the previous show is on a Friday or not - catering for
    weekends in other words!

templates/queries-index-mysql.tpl.html,
templates/queries-index-sqlite.tpl.html: using a 'find unused index
    numbers' query available in many places on the Internet, but
    modified to return the id number and date for the show *before* the
    next free slot.
This commit is contained in:
Dave Morriss 2023-11-17 18:23:22 +00:00
parent 0ef92840c8
commit e5b5aac104
3 changed files with 26 additions and 7 deletions

View File

@ -32,13 +32,8 @@
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% USE date %--> <!--% USE date %-->
<!--% calc = date.calc %--> <!--% calc = date.calc %-->
<!--% episodes = DBI.query("SELECT id, date FROM eps WHERE date >= date('now') ORDER BY id").get_all() %--> <!--% episodes = DBI.query(query_next_available_episode).get_all() %-->
<!--% ind = episodes.0.id %--> <!--% last_date = episodes.0.date.split('-') %-->
<!--% FOREACH ep IN episodes %-->
<!--% LAST IF ep.id != ind %-->
<!--% last_date = ep.date.split('-') %-->
<!--% ind = ind+1 %-->
<!--% END %-->
<!--% offset = (calc.Day_of_Week(last_date.0,last_date.1,last_date.2) == 5 ? 3 : 1) %--> <!--% offset = (calc.Day_of_Week(last_date.0,last_date.1,last_date.2) == 5 ? 3 : 1) %-->
<!--% slot_date = calc.Add_Delta_Days(last_date.0,last_date.1,last_date.2,offset) %--> <!--% slot_date = calc.Add_Delta_Days(last_date.0,last_date.1,last_date.2,offset) %-->
<!--% now = calc.Today() %--> <!--% now = calc.Today() %-->

View File

@ -1,3 +1,15 @@
<!--% query_next_available_episode = '
SELECT id, date FROM eps e WHERE id = (
SELECT id + 1 FROM eps mo
WHERE NOT EXISTS (
SELECT NULL
FROM eps mi
WHERE mi.id = mo.id + 1
)
ORDER BY id
LIMIT 1) - 1
'
%-->
<!--% query_latest_episodes = ' <!--% query_latest_episodes = '
WITH comment_tallies AS ( WITH comment_tallies AS (
SELECT SELECT

View File

@ -1,3 +1,15 @@
<!--% query_next_available_episode = '
SELECT id, date FROM eps e WHERE id = (
SELECT id + 1 FROM eps mo
WHERE NOT EXISTS (
SELECT NULL
FROM eps mi
WHERE mi.id = mo.id + 1
)
ORDER BY id
LIMIT 1) - 1
'
%-->
<!--% query_latest_episodes = ' <!--% query_latest_episodes = '
WITH comment_tallies AS ( WITH comment_tallies AS (
SELECT SELECT