Skip to content

Commit

Permalink
Merge pull request #3054 from Maxr1998/patch-1
Browse files Browse the repository at this point in the history
Add back `inserted_at` field to export
  • Loading branch information
MonkeyDo authored Jan 14, 2025
2 parents c67be5d + c0ce031 commit 4b65efc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions listenbrainz/background/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def export_listens_for_time_range(ts_conn, file_path, user_id: int, start_time:
query = """
WITH selected_listens AS (
SELECT l.listened_at
, l.created as inserted_at
, l.data
, l.recording_msid
, COALESCE((data->'additional_info'->>'recording_mbid')::uuid, user_mm.recording_mbid, mm.recording_mbid, other_mm.recording_mbid) AS recording_mbid
Expand All @@ -97,6 +98,8 @@ def export_listens_for_time_range(ts_conn, file_path, user_id: int, start_time:
SELECT jsonb_build_object(
'listened_at'
, extract(epoch from listened_at)
, 'inserted_at'
, extract(epoch from inserted_at)
, 'track_metadata'
, jsonb_set(
jsonb_set(data, '{recording_msid}'::text[], to_jsonb(recording_msid::text)),
Expand Down Expand Up @@ -140,6 +143,7 @@ def export_listens_for_time_range(ts_conn, file_path, user_id: int, start_time:
LEFT JOIN LATERAL jsonb_array_elements(artist_data->'artists') WITH ORDINALITY artists(artist, position)
ON TRUE
GROUP BY sl.listened_at
, sl.inserted_at
, sl.recording_msid
, sl.data
, mbc.recording_mbid
Expand Down
4 changes: 4 additions & 0 deletions listenbrainz/tests/integration/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def test_export(self):
self.assertEqual(expected["track_metadata"]["artist_name"], received["track_metadata"]["artist_name"])
self.assertEqual(expected["track_metadata"]["release_name"], received["track_metadata"]["release_name"])
self.assertEqual(expected["listened_at"], received["listened_at"])
# The test data used in send_listens cannot have an inserted_at prop as that is not a valid listen format
self.assertNotIn("inserted_at", expected)
# However inserted_at should be part of the exported listen data
self.assertIn("inserted_at", received)
if received["track_metadata"]["track_name"] == "Sister":
self.assertEqual({
"caa_id": self.recording["release_data"]["caa_id"],
Expand Down

0 comments on commit 4b65efc

Please sign in to comment.