Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion discovery-provider/es-indexer/src/indexNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export const indexNames = {
playlists: 'playlists18',
reposts: 'reposts13',
saves: 'saves13',
tracks: 'tracks15',
tracks: 'tracks16',
users: 'users16',
}
5 changes: 5 additions & 0 deletions discovery-provider/es-indexer/src/indexers/TrackIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class TrackIndexer extends BaseIndexer<TrackDoc> {
is_delete: { type: 'boolean' },
is_unlisted: { type: 'boolean' },
downloadable: { type: 'boolean' },
purchaseable: { type: 'boolean' },

// saves
saved_by: { type: 'keyword' },
Expand Down Expand Up @@ -94,6 +95,10 @@ export class TrackIndexer extends BaseIndexer<TrackDoc> {
-- etl tracks
select
tracks.*,
case when tracks.premium_conditions->>'usdc_purchase'
is not null then true
else false
end as purchaseable,
(tracks.download->>'is_downloadable')::boolean as downloadable,
coalesce(aggregate_plays.count, 0) as play_count,

Expand Down
1 change: 1 addition & 0 deletions discovery-provider/es-indexer/src/types/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type TrackDoc = TrackRow & {
favorite_count: number
play_count: any // todo: is it a string or number? pg returns string
downloadable: boolean
purchaseable: boolean
user: EntityUserDoc
duration: number
}
Expand Down
48 changes: 48 additions & 0 deletions discovery-provider/integration_tests/queries/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def setup_search(app_module):
blockhash=hex(3),
number=3,
parenthash="0x03",
is_current=False,
),
Block(
blockhash=hex(4),
number=4,
parenthash="0x04",
is_current=True,
),
]
Expand Down Expand Up @@ -94,6 +100,28 @@ def setup_search(app_module):
title="xyz",
download={"cid": None, "is_downloadable": True, "requires_follow": False},
),
Track(
blockhash=hex(4),
blocknumber=4,
track_id=4,
is_current=True,
is_delete=False,
owner_id=1,
route_id="",
track_segments=[],
genre="",
updated_at=now,
created_at=now,
is_unlisted=False,
title="the track 4",
download={"cid": None, "is_downloadable": True, "requires_follow": False},
premium_conditions={
"usdc_purchase": {
"price": 100,
"splits": {"4hbyJjqpWAbarjCQhY8YSeptZz1WYSS88DGqG4BteE3v": 1000000},
}
},
),
]

users = [
Expand Down Expand Up @@ -328,6 +356,26 @@ def test_get_downloadable_tracks(app_module):
assert len(es_res["saved_tracks"]) == 0


def test_get_tracks_with_purchases(app_module):
"""Tests we get results with purchaseable tracks"""

search_args = {
"is_auto_complete": True,
"kind": "tracks",
"query": "the track",
"current_user_id": None,
"with_users": True,
"limit": 10,
"offset": 0,
"only_downloadable": False,
"include_purchaseable": True,
}
es_res = search_es_full(search_args)

assert len(es_res["tracks"]) == 3
assert es_res["tracks"][2]["track_id"] == 4


def test_get_external_users(app_module):
"""Tests we get all users"""

Expand Down
6 changes: 6 additions & 0 deletions discovery-provider/src/api/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,12 @@ def add_auth_headers_to_parser(parser):
choices=("all", "users", "tracks", "playlists", "albums"),
description="The type of response, one of: all, users, tracks, playlists, or albums",
)
full_search_parser.add_argument(
"includePurchaseable",
required=False,
type=bool,
description="Whether or not to include purchaseable content",
)

verify_token_parser = reqparse.RequestParser(argument_class=DescriptiveArgument)
verify_token_parser.add_argument("token", required=True, description="JWT to verify")
Expand Down
2 changes: 2 additions & 0 deletions discovery-provider/src/api/v1/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def get(self):
"limit": limit,
"offset": offset,
"only_downloadable": False,
"include_purchaseable": args.get("includePurchaseable", False),
}
resp = search(search_args)
return success_response(resp)
Expand Down Expand Up @@ -93,6 +94,7 @@ def get(self):
"limit": limit,
"offset": offset,
"only_downloadable": False,
"include_purchaseable": args.get("includePurchaseable", False),
}
resp = search(search_args)
return success_response(resp)
7 changes: 7 additions & 0 deletions discovery-provider/src/queries/search_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def search_es_full(args: dict):
search_type = args.get("kind", "all")
only_downloadable = args.get("only_downloadable")
is_auto_complete = args.get("is_auto_complete")
include_purchaseable = args.get("include_purchaseable", False)
do_tracks = search_type == "all" or search_type == "tracks"
do_users = search_type == "all" or search_type == "users"
do_playlists = search_type == "all" or search_type == "playlists"
Expand All @@ -50,6 +51,7 @@ def search_es_full(args: dict):
current_user_id=current_user_id,
must_saved=False,
only_downloadable=only_downloadable,
include_purchaseable=include_purchaseable,
),
]
)
Expand All @@ -64,6 +66,7 @@ def search_es_full(args: dict):
current_user_id=current_user_id,
must_saved=True,
only_downloadable=only_downloadable,
include_purchaseable=include_purchaseable,
),
]
)
Expand Down Expand Up @@ -369,6 +372,7 @@ def track_dsl(
current_user_id,
must_saved=False,
only_downloadable=False,
include_purchaseable=False,
):
dsl = {
"must": [
Expand All @@ -395,6 +399,9 @@ def track_dsl(
if only_downloadable:
dsl["must"].append({"term": {"downloadable": {"value": True}}})

if not include_purchaseable:
dsl["must_not"].append({"term": {"purchaseable": {"value": True}}})

personalize_dsl(dsl, current_user_id, must_saved)
return default_function_score(dsl, "repost_count")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ type GetSearchArgs = {
kind?: SearchKind
limit?: number
offset?: number
includePurchaseable?: boolean
}

type TrendingIdsResponse = {
Expand Down Expand Up @@ -1350,7 +1351,8 @@ export class AudiusAPIClient {
query,
kind,
offset,
limit
limit,
includePurchaseable
}: GetSearchArgs) {
this._assertInitialized()
const encodedUserId = encodeHashId(currentUserId)
Expand All @@ -1359,7 +1361,8 @@ export class AudiusAPIClient {
query,
kind,
offset,
limit
limit,
includePurchaseable
}

const searchResponse =
Expand All @@ -1377,7 +1380,8 @@ export class AudiusAPIClient {
query,
kind,
offset,
limit
limit,
includePurchaseable
}: GetSearchArgs) {
this._assertInitialized()
const encodedUserId = encodeHashId(currentUserId)
Expand All @@ -1386,7 +1390,8 @@ export class AudiusAPIClient {
query,
kind,
offset,
limit
limit,
includePurchaseable
}

const searchResponse =
Expand Down
14 changes: 11 additions & 3 deletions packages/web/src/common/store/pages/search-page/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
searchResultsPageTracksLineupActions as tracksLineupActions,
SearchKind,
processAndCacheUsers,
removeNullable
removeNullable,
FeatureFlags
} from '@audius/common'
import { flatMap, zip } from 'lodash'
import {
Expand Down Expand Up @@ -103,6 +104,11 @@ const searchMultiMap = {

export function* getSearchResults(searchText, kind, limit, offset) {
yield waitForRead()
const getFeatureEnabled = yield getContext('getFeatureEnabled')
const isUSDCEnabled = yield call(
getFeatureEnabled,
FeatureFlags.USDC_PURCHASES
)

const apiClient = yield getContext('apiClient')
const userId = yield select(getUserId)
Expand All @@ -114,7 +120,8 @@ export function* getSearchResults(searchText, kind, limit, offset) {
query,
kind,
limit,
offset
offset,
includePurchaseable: isUSDCEnabled
})
)
const allSearchResults = yield all(searches)
Expand All @@ -136,7 +143,8 @@ export function* getSearchResults(searchText, kind, limit, offset) {
query: searchText,
kind,
limit,
offset
offset,
includePurchaseable: isUSDCEnabled
})
}
const { tracks, albums, playlists, users } = results
Expand Down
12 changes: 5 additions & 7 deletions packages/web/src/common/store/search-bar/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function* getSearchResults(searchText: string) {
currentUserId: userId,
query,
limit: 3,
offset: 0
offset: 0,
includePurchaseable: isUSDCEnabled
})
)
const allSearchResults = yield* all(searches)
Expand All @@ -72,18 +73,15 @@ export function* getSearchResults(searchText: string) {
currentUserId: userId,
query: searchText,
limit: 3,
offset: 0
offset: 0,
includePurchaseable: isUSDCEnabled
})
}

const { tracks, albums, playlists, users } = results
const checkedUsers = users.filter((u) => !u.is_deactivated)
const checkedTracks = tracks.filter((t) => {
return (
!t.is_delete &&
!t.user.is_deactivated &&
(isUSDCEnabled || !('usdc_purchase' in (t.premium_conditions || {})))
)
return !t.is_delete && !t.user.is_deactivated
})
const checkedPlaylists = playlists.filter((p) => !p.user?.is_deactivated)
const checkedAlbums = albums.filter((a) => !a.user?.is_deactivated)
Expand Down