Revert "DRY: fix duplicate code for Recommended key generation"
This reverts commit 05376490a8
.
This commit is contained in:
parent
4cf531b8ad
commit
5fe5f7599f
2 changed files with 25 additions and 20 deletions
|
@ -1,5 +1,7 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import { getSearchQueryString } from 'util/query-params';
|
||||||
import { selectShowMatureContent } from 'redux/selectors/settings';
|
import { selectShowMatureContent } from 'redux/selectors/settings';
|
||||||
|
import { SEARCH_OPTIONS } from 'constants/search';
|
||||||
import {
|
import {
|
||||||
selectClaimsByUri,
|
selectClaimsByUri,
|
||||||
makeSelectClaimForUri,
|
makeSelectClaimForUri,
|
||||||
|
@ -12,10 +14,11 @@ import { parseURI } from 'util/lbryURI';
|
||||||
import { isClaimNsfw } from 'util/claim';
|
import { isClaimNsfw } from 'util/claim';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { createCachedSelector } from 're-reselect';
|
import { createCachedSelector } from 're-reselect';
|
||||||
import { createNormalizedSearchKey, getRecommendationSearchKey, getRecommendationSearchOptions } from 'util/search';
|
import { createNormalizedSearchKey, getRecommendationSearchOptions } from 'util/search';
|
||||||
import { selectMutedChannels } from 'redux/selectors/blocked';
|
import { selectMutedChannels } from 'redux/selectors/blocked';
|
||||||
import { selectHistory } from 'redux/selectors/content';
|
import { selectHistory } from 'redux/selectors/content';
|
||||||
import { selectAllCostInfoByUri } from 'lbryinc';
|
import { selectAllCostInfoByUri } from 'lbryinc';
|
||||||
|
import { SIMPLE_SITE } from 'config';
|
||||||
|
|
||||||
type State = { claims: any, search: SearchState, user: UserState };
|
type State = { claims: any, search: SearchState, user: UserState };
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ export const selectRecommendedContentForUri = createCachedSelector(
|
||||||
selectClaimIsNsfwForUri, // (state, uri)
|
selectClaimIsNsfwForUri, // (state, uri)
|
||||||
(uri, history, claimsByUri, matureEnabled, blockedChannels, costInfoByUri, searchUrisByQuery, isMature) => {
|
(uri, history, claimsByUri, matureEnabled, blockedChannels, costInfoByUri, searchUrisByQuery, isMature) => {
|
||||||
const claim = claimsByUri[uri];
|
const claim = claimsByUri[uri];
|
||||||
|
|
||||||
if (!claim) return;
|
if (!claim) return;
|
||||||
|
|
||||||
let recommendedContent;
|
let recommendedContent;
|
||||||
|
@ -70,10 +74,26 @@ export const selectRecommendedContentForUri = createCachedSelector(
|
||||||
const currentClaimId = claim.claim_id;
|
const currentClaimId = claim.claim_id;
|
||||||
|
|
||||||
const { title } = claim.value;
|
const { title } = claim.value;
|
||||||
|
|
||||||
if (!title) return;
|
if (!title) return;
|
||||||
|
|
||||||
const options = getRecommendationSearchOptions(matureEnabled, isMature, claim.claim_id);
|
const options: {
|
||||||
const normalizedSearchQuery = getRecommendationSearchKey(title, options);
|
size: number,
|
||||||
|
nsfw?: boolean,
|
||||||
|
isBackgroundSearch?: boolean,
|
||||||
|
} = { size: 20, nsfw: matureEnabled, isBackgroundSearch: true };
|
||||||
|
|
||||||
|
if (SIMPLE_SITE) {
|
||||||
|
options[SEARCH_OPTIONS.CLAIM_TYPE] = SEARCH_OPTIONS.INCLUDE_FILES;
|
||||||
|
options[SEARCH_OPTIONS.MEDIA_VIDEO] = true;
|
||||||
|
options[SEARCH_OPTIONS.PRICE_FILTER_FREE] = true;
|
||||||
|
}
|
||||||
|
if (matureEnabled || (!matureEnabled && !isMature)) {
|
||||||
|
options[SEARCH_OPTIONS.RELATED_TO] = claim.claim_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
|
||||||
|
const normalizedSearchQuery = createNormalizedSearchKey(searchQuery);
|
||||||
|
|
||||||
let searchResult = searchUrisByQuery[normalizedSearchQuery];
|
let searchResult = searchUrisByQuery[normalizedSearchQuery];
|
||||||
|
|
||||||
|
@ -149,7 +169,8 @@ export const makeSelectRecommendedRecsysIdForClaimId = (claimId: string) =>
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = getRecommendationSearchOptions(matureEnabled, isMature, claimId);
|
const options = getRecommendationSearchOptions(matureEnabled, isMature, claimId);
|
||||||
const normalizedSearchQuery = getRecommendationSearchKey(title, options);
|
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
|
||||||
|
const normalizedSearchQuery = createNormalizedSearchKey(searchQuery);
|
||||||
|
|
||||||
const searchResult = searchUrisByQuery[normalizedSearchQuery];
|
const searchResult = searchUrisByQuery[normalizedSearchQuery];
|
||||||
if (searchResult) {
|
if (searchResult) {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import { isNameValid, isURIValid, normalizeURI, parseURI } from 'util/lbryURI';
|
import { isNameValid, isURIValid, normalizeURI, parseURI } from 'util/lbryURI';
|
||||||
import { URL as SITE_URL, URL_LOCAL, URL_DEV, SIMPLE_SITE } from 'config';
|
import { URL as SITE_URL, URL_LOCAL, URL_DEV, SIMPLE_SITE } from 'config';
|
||||||
import { SEARCH_OPTIONS } from 'constants/search';
|
import { SEARCH_OPTIONS } from 'constants/search';
|
||||||
import { getSearchQueryString } from 'util/query-params';
|
|
||||||
|
|
||||||
export function createNormalizedSearchKey(query: string) {
|
export function createNormalizedSearchKey(query: string) {
|
||||||
const removeParam = (query: string, param: string) => {
|
const removeParam = (query: string, param: string) => {
|
||||||
|
@ -98,16 +97,6 @@ export function getUriForSearchTerm(term: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The 'Recommended' search query is used as the key to store the results. This
|
|
||||||
* function ensures all clients derive the same key by making this the only
|
|
||||||
* place to make tweaks.
|
|
||||||
*
|
|
||||||
* @param matureEnabled
|
|
||||||
* @param claimIsMature
|
|
||||||
* @param claimId
|
|
||||||
* @returns {{size: number, nsfw: boolean, isBackgroundSearch: boolean}}
|
|
||||||
*/
|
|
||||||
export function getRecommendationSearchOptions(matureEnabled: boolean, claimIsMature: boolean, claimId: string) {
|
export function getRecommendationSearchOptions(matureEnabled: boolean, claimIsMature: boolean, claimId: string) {
|
||||||
const options = { size: 20, nsfw: matureEnabled, isBackgroundSearch: true };
|
const options = { size: 20, nsfw: matureEnabled, isBackgroundSearch: true };
|
||||||
|
|
||||||
|
@ -123,8 +112,3 @@ export function getRecommendationSearchOptions(matureEnabled: boolean, claimIsMa
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRecommendationSearchKey(title: string, options: {}) {
|
|
||||||
const searchQuery = getSearchQueryString(title.replace(/\//, ' '), options);
|
|
||||||
return createNormalizedSearchKey(searchQuery);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue