[Audio] Move playlist from the Config Driver to their own SQL table #3195

Closed
Drapersniper wants to merge 28 commits from playlists into V3/develop
Drapersniper commented 2019-12-18 12:28:03 +01:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

Okay so this should in theory significantly improve audio performance across the border for folks that use the playlist function

@PredaaA using Mart on dev which has #2921 (which significantly reduces JSON size went from 50+MB prior to #2921 to 18.6MB prior to this PR)

With this PR his audio config went from 18.6MB to 287.12 KB... (and say we want to also migrate the EQUALIZER scope to an SQL table ... his config was reduced to 42.97 KB) which should significantly reduce write times and overall make audio commands feel speedier.

### Type - [ ] Bugfix - [x] Enhancement - [ ] New feature ### Description of the changes Okay so this should in theory significantly improve audio performance across the border for folks that use the playlist function @PredaaA using Mart on dev which has #2921 (which significantly reduces JSON size went from 50+MB prior to #2921 to 18.6MB prior to this PR) With this PR his audio config went from 18.6MB to 287.12 KB... (and say we want to also migrate the EQUALIZER scope to an SQL table ... his config was reduced to 42.97 KB) which should significantly reduce write times and overall make audio commands feel speedier.
Twentysix26 (Migrated from github.com) reviewed 2019-12-18 12:28:03 +01:00
Drapersniper commented 2019-12-18 12:30:29 +01:00 (Migrated from github.com)

Note: This was supposed to be a draft ... as still pending some testing ... I'll update it when its ready for a review

Note: This was supposed to be a draft ... as still pending some testing ... I'll update it when its ready for a review
Drapersniper commented 2019-12-18 12:40:08 +01:00 (Migrated from github.com)

This will keep failing until #3192 is merged due to the apsw dep

This will keep failing until #3192 is merged due to the apsw dep
mikeshardmind commented 2019-12-20 08:24:40 +01:00 (Migrated from github.com)

Note for future improvement.

Changes here are a drastic improvement in performance, and once ready for use, they should be merged without waiting on adapting everything for the below.

However, long term a schema like the below should be used

CREATE TABLE IF NOT EXISTS playlists(
  playlist_id INTEGER PRIMARY KEY,
  playlist_name TEXT NOT NULL,
  scope_type TEXT NOT NULL,  -- INTEGER preferable*
  scope_id INTEGER NOT NULL, -- author or guild id
  owner_id INTEGER NOT NULL, -- Used to determine creator for UI
);

CREATE TABLE IF NOT EXISTS tracks(
  track_id INTEGER PRIMARY KEY,
  track_data JSON
);

CREATE TABLE IF NOT EXISTS track_relations(
  track_id INTEGER REFERENCES(tracks.track_id) ON DELETE CASCADE,
  playlist_id REFERENCES(playlists.playlist_id) ON DELETE CASCADE,
  track_number INTEGER, -- for playlist ordering
  PRIMARY KEY(track_id, playlist_id)
);

With queries changing to something such as:

-- fetch playlist tracks
SELECT tracks.track_data, track_relations.track_number
FROM tracks 
  INNER JOIN track_relations
  ON tracks.track_id=tracks_relations.track_id
WHERE track_relations.playlist_id = ?;

Search query gets a little more complicated, but won't be used as often and will still be faster:

-- search playlists by name
SELECT
  playlists.playlist_name,
  playlists.owner_id,
  playlists.playlist_id,
  COUNT(track_relations.track_id)
FROM playlists 
  LEFT INNER JOIN track_relations ON playlists.playlist_id=track_relations.playlist_id
GROUP BY playlists.playlist_id
-- query doesn't have to be provided
WHERE
  playlists.scope_id = :scope_id 
  AND playlists.scope_type = :scope_type
  AND playlists.playlist_name LIKE "%" || COALESCE(:query, "") || "%";
Note for future improvement. Changes here are a drastic improvement in performance, and once ready for use, they should be merged without waiting on adapting everything for the below. However, long term a schema like the below should be used ```sql CREATE TABLE IF NOT EXISTS playlists( playlist_id INTEGER PRIMARY KEY, playlist_name TEXT NOT NULL, scope_type TEXT NOT NULL, -- INTEGER preferable* scope_id INTEGER NOT NULL, -- author or guild id owner_id INTEGER NOT NULL, -- Used to determine creator for UI ); CREATE TABLE IF NOT EXISTS tracks( track_id INTEGER PRIMARY KEY, track_data JSON ); CREATE TABLE IF NOT EXISTS track_relations( track_id INTEGER REFERENCES(tracks.track_id) ON DELETE CASCADE, playlist_id REFERENCES(playlists.playlist_id) ON DELETE CASCADE, track_number INTEGER, -- for playlist ordering PRIMARY KEY(track_id, playlist_id) ); ``` With queries changing to something such as: ```sql -- fetch playlist tracks SELECT tracks.track_data, track_relations.track_number FROM tracks INNER JOIN track_relations ON tracks.track_id=tracks_relations.track_id WHERE track_relations.playlist_id = ?; ``` Search query gets a little more complicated, but won't be used as often and will still be faster: ```sql -- search playlists by name SELECT playlists.playlist_name, playlists.owner_id, playlists.playlist_id, COUNT(track_relations.track_id) FROM playlists LEFT INNER JOIN track_relations ON playlists.playlist_id=track_relations.playlist_id GROUP BY playlists.playlist_id -- query doesn't have to be provided WHERE playlists.scope_id = :scope_id AND playlists.scope_type = :scope_type AND playlists.playlist_name LIKE "%" || COALESCE(:query, "") || "%"; ```
Drapersniper commented 2019-12-21 20:09:21 +01:00 (Migrated from github.com)

Do not merge this one ... Merge #3205

Do not merge this one ... Merge #3205
Drapersniper commented 2019-12-22 16:40:55 +01:00 (Migrated from github.com)

Will setup a CPR for all of this so itsd easier to follow ... less likely to fuck up)

Will setup a CPR for all of this so itsd easier to follow ... less likely to fuck up)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!3195
No description provided.