sintonia/legacy/application/models
Rob Hailman 2b43e51ed1
fix: playlist allocates inaccurate time to smartblocks (#3026)
### Description

In the existing logic of `retrieveMediaFiles`, the time remaining in
show is calculated incorrectly in some scenarios. Each time a duration
is subtracted from `showLimit`, it is not the duration of the files just
added, but instead the length of all files scheduled. This can cause
cases where a smart block set to "time remaining in show" fails to
completely fill the program.

For example, given a 30 minute show, and a playlist like follows:

1. a 5 minute track
2. another 5 minute track
3. smart block, set to time remaining in show

When item 1 is added, `showLimit` is reduced by 5 minutes as expected.
When item 2 is added, `showLimit` is reduced by 10 minutes (as both
items 1 and 2 are counted). As a result, the smart block is only run to
fill 15 minutes, leaving 5 minutes unfilled.

This PR resolves this issue, by recalculating `showLimit` from the
original duration rather than subtracting from a running total.

This change not does implement a new feature and should not require any
changes to documentation.

### Testing Notes

**What I did:**

- On a dev environment, set up a playlist as described above.
- Before applying this PR, created a show and scheduled playlist, and
confirmed issue was reproducible
- Applied PR and repeated, and confirmed show was filled completely.

Also repeated this testing with sample data from our production
instance.

Here is a sample schedule of the "before" case with sample data, showing
the issue

![image](https://github.com/libretime/libretime/assets/8541186/f91849fb-606f-410e-bef5-a7abc8e7b7f4)
The smartblock that scheduled the music is set to allow last track to
overflow, but 3m55s was left unscheduled.

Using the same playlist and same track library, here is a sample
schedule after the PR applied:

![image](https://github.com/libretime/libretime/assets/8541186/e9d46fbb-50e6-4859-a3de-f5a90a6021c0)
As expected, the show is fully scheduled with the last track
overflowing.
 
Additionally, I've applied this PR as a hot fix to our production
instance, where it has been running for a week without issue.

Also performed spot tests of playlists without smart blocks, smart
blocks scheduled directly (not in playlists) and autoloading playlists,
with no change in behaviour observed as a result of this change.

**How you can replicate my testing:**

Same test steps as I followed should be able to reproduce issue &
validate fix on any instance.

### **Links**

Not directly related to issue fixed by #3019, but also addresses the
issue of dead air left at end of blocks.

Co-authored-by: Kyle Robbertze <paddatrapper@users.noreply.github.com>
2024-06-05 17:01:57 +01:00
..
airtime fix(deps): update dependency friendsofphp/php-cs-fixer to <3.53.1 (#2972) 2024-04-13 14:36:31 +02:00
formatters style(legacy): fix code format with php-cs-fixer (#1674) 2022-03-14 12:15:04 +02:00
tests feat: build schedule events exclusively in playout (#2946) 2024-04-27 20:09:16 +02:00
Auth.php feat(legacy): move session store to database (#2523) 2023-05-30 22:25:50 +02:00
Block.php fix(legacy): ensure last played criteria works with never played files (#2840) 2023-12-27 17:32:33 +01:00
Dashboard.php style(legacy): format files (#1946) 2022-07-07 20:01:15 +02:00
Datatables.php fix(legacy): advanced search by track type id 2023-01-08 22:40:48 +02:00
Email.php Format code using php-cs-fixer 2021-10-12 11:07:56 +02:00
FreeIpa.php Format code using php-cs-fixer 2021-10-12 11:07:56 +02:00
Library.php fix: use constrained foreign key for files track_type 2022-07-07 21:07:41 +02:00
LibraryEditable.php Format code using php-cs-fixer 2021-10-12 11:07:56 +02:00
ListenerStat.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.26.1 (main) (#2677) 2023-09-08 15:45:24 +02:00
LiveLog.php style(legacy): format files (#1946) 2022-07-07 20:01:15 +02:00
Locale.php feat(legacy): add Ukrainian language 2022-07-04 20:00:51 +02:00
LoginAttempts.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.26.1 (main) (#2677) 2023-09-08 15:45:24 +02:00
Playlist.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.27.1 (main) (#2714) 2023-09-17 17:14:59 +02:00
Preference.php fix(legacy): replay_gain_modifier should be a system preference (#2943) 2024-02-08 19:48:49 +01:00
RabbitMq.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.46.1 (main) (#2868) 2024-01-07 13:59:02 +01:00
Schedule.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.27.1 (main) (#2714) 2023-09-17 17:14:59 +02:00
Scheduler.php fix: playlist allocates inaccurate time to smartblocks (#3026) 2024-06-05 17:01:57 +01:00
ServiceRegister.php fix(legacy): update or remove broken links 2022-09-21 08:28:43 +02:00
Show.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.23.1 (stable) (#2656) 2023-08-15 18:28:18 +02:00
ShowBuilder.php style(legacy): format files (#1946) 2022-07-07 20:01:15 +02:00
ShowInstance.php feat(legacy): trim overbooked shows after autoloading a playlist (#2897) 2024-02-02 20:17:23 +01:00
StoredFile.php fix(legacy): allow deleting file with api token (#2995) 2024-05-05 22:26:27 +02:00
StreamSetting.php feat: add mobile devices stream config field (#2744) 2023-10-14 08:13:04 +01:00
Subjects.php chore: use https links (#2075) 2022-08-25 16:25:54 +02:00
Systemstatus.php chore(legacy): format code 2022-09-12 14:15:50 +02:00
Tracktype.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.27.1 (main) (#2714) 2023-09-17 17:14:59 +02:00
User.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.43.2 (main) (#2848) 2023-12-29 15:28:57 +01:00
Webstream.php fix(deps): update dependency friendsofphp/php-cs-fixer to <3.27.1 (main) (#2714) 2023-09-17 17:14:59 +02:00