[3.2.3][Audio] Full fix for #3328 (#3355)

* Limit Playlists

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* Hotfix

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* Hotfix

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* [Audio] Hotfix an edge case where an attribute error can be raised (#3328)

* Limit Playlists

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* Hotfix

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* Hotfix

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* flame's review

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* Delete 3328.hotfix.1.rst

* lets be extra safe here

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
Draper 2020-01-12 22:37:50 +00:00 committed by Michael H
parent d6936c87f3
commit fdfbfe7b60
3 changed files with 46 additions and 34 deletions

View File

@ -0,0 +1 @@
Check data before it is inserted into the database to avoid corruption.

View File

@ -746,13 +746,13 @@ class MusicCache:
(val, update) = await self.database.fetch_one("lavalink", "data", {"query": query})
if update:
val = None
if val and not isinstance(val, str):
if val and isinstance(val, dict):
log.debug(f"Querying Local Database for {query}")
task = ("update", ("lavalink", {"query": query}))
self.append_task(ctx, *task)
else:
val = None
if val and not forced:
if val and not forced and isinstance(val, dict):
data = val
data["query"] = query
results = LoadResult(data)
@ -780,6 +780,10 @@ class MusicCache:
):
with contextlib.suppress(SQLError):
time_now = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
data = json.dumps(results._raw)
if all(
k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
):
task = (
"insert",
(
@ -787,7 +791,7 @@ class MusicCache:
[
{
"query": query,
"data": json.dumps(results._raw),
"data": data,
"last_updated": time_now,
"last_fetched": time_now,
}
@ -855,7 +859,7 @@ class MusicCache:
query_data["maxage"] = maxage_int
vals = await self.database.fetch_all("lavalink", "data", query_data)
recently_played = [r.tracks for r in vals if r]
recently_played = [r.tracks for r in vals if r if isinstance(tracks, dict)]
if recently_played:
track = random.choice(recently_played)

View File

@ -246,10 +246,15 @@ class Audio(commands.Cog):
uri = t.get("info", {}).get("uri")
if uri:
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
data = json.dumps(t)
if all(
k in data
for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]
):
database_entries.append(
{
"query": uri,
"data": json.dumps(t),
"data": data,
"last_updated": time_now,
"last_fetched": time_now,
}
@ -5883,10 +5888,12 @@ class Audio(commands.Cog):
uri = t.get("info", {}).get("uri")
if uri:
t = {"loadType": "V2_COMPACT", "tracks": [t], "query": uri}
data = json.dumps(t)
if all(k in data for k in ["loadType", "playlistInfo", "isSeekable", "isStream"]):
database_entries.append(
{
"query": uri,
"data": json.dumps(t),
"data": data,
"last_updated": time_now,
"last_fetched": time_now,
}