Route recommendation search to recsys + add user_id (#353)

* Route recommendation search to recsys 5% of the time + add `user_id`

## Ticket
334 send some recommended requests to recsys

## Approach
`doSearch`:
    - If the search options include `related_to`, route that to the new `searchRecommendations` which performs the 5% check + appends `user_id` at the end. This way, we don't need to alter the function signature of `doSearch`.
    - Else, run proceed as normal.

* Always go to alt provider

f

Co-authored-by: Thomas Zarebczan <thomas.zarebczan@gmail.com>
This commit is contained in:
infinite-persistence 2021-11-24 12:25:22 -08:00 committed by GitHub
parent 2adbbc2899
commit fd17ab4c8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 6 deletions

View file

@ -14,6 +14,7 @@ LBRY_WEB_BUFFER_API=https://collector-service.api.lbry.tv/api/v1/events/video
COMMENT_SERVER_API=https://comments.odysee.com/api/v2 COMMENT_SERVER_API=https://comments.odysee.com/api/v2
COMMENT_SERVER_NAME=Odysee COMMENT_SERVER_NAME=Odysee
SEARCH_SERVER_API=https://lighthouse.odysee.com/search SEARCH_SERVER_API=https://lighthouse.odysee.com/search
SEARCH_SERVER_API_ALT=https://recsys.odysee.com/search
SOCKETY_SERVER_API=wss://sockety.odysee.com/ws SOCKETY_SERVER_API=wss://sockety.odysee.com/ws
THUMBNAIL_CDN_URL=https://thumbnails.odysee.com/optimize/ THUMBNAIL_CDN_URL=https://thumbnails.odysee.com/optimize/
THUMBNAIL_CARDS_CDN_URL=https://cards.odysee.com/ THUMBNAIL_CARDS_CDN_URL=https://cards.odysee.com/

View file

@ -13,6 +13,7 @@ const config = {
LBRY_WEB_STREAMING_API: process.env.LBRY_WEB_STREAMING_API, //cdn.lbryplayer.xyz', LBRY_WEB_STREAMING_API: process.env.LBRY_WEB_STREAMING_API, //cdn.lbryplayer.xyz',
LBRY_WEB_BUFFER_API: process.env.LBRY_WEB_BUFFER_API, LBRY_WEB_BUFFER_API: process.env.LBRY_WEB_BUFFER_API,
SEARCH_SERVER_API: process.env.SEARCH_SERVER_API, SEARCH_SERVER_API: process.env.SEARCH_SERVER_API,
SEARCH_SERVER_API_ALT: process.env.SEARCH_SERVER_API_ALT,
COMMENT_SERVER_API: process.env.COMMENT_SERVER_API, COMMENT_SERVER_API: process.env.COMMENT_SERVER_API,
COMMENT_SERVER_NAME: process.env.COMMENT_SERVER_NAME, COMMENT_SERVER_NAME: process.env.COMMENT_SERVER_NAME,
SOCKETY_SERVER_API: process.env.SOCKETY_SERVER_API, SOCKETY_SERVER_API: process.env.SOCKETY_SERVER_API,

View file

@ -4,6 +4,7 @@ import React, { useEffect, useRef, useState, useLayoutEffect } from 'react';
import { lazyImport } from 'util/lazyImport'; import { lazyImport } from 'util/lazyImport';
import classnames from 'classnames'; import classnames from 'classnames';
import analytics from 'analytics'; import analytics from 'analytics';
import { setSearchUserId } from 'redux/actions/search';
import { buildURI, parseURI } from 'util/lbryURI'; import { buildURI, parseURI } from 'util/lbryURI';
import { SIMPLE_SITE } from 'config'; import { SIMPLE_SITE } from 'config';
import Router from 'component/router/index'; import Router from 'component/router/index';
@ -214,6 +215,7 @@ function App(props: Props) {
useEffect(() => { useEffect(() => {
if (userId) { if (userId) {
analytics.setUser(userId); analytics.setUser(userId);
setSearchUserId(userId);
} }
}, [userId]); }, [userId]);

View file

@ -112,7 +112,7 @@ export default function YoutubeTransferStatus(props: Props) {
!hasPendingTransfers && !hasPendingTransfers &&
!isYoutubeTransferComplete && !isYoutubeTransferComplete &&
!isNotElligible && !isNotElligible &&
__('Please check back later. This may take up to 1 week.')} __('Please check back later, this may take a few hours.')}
{isYoutubeTransferComplete && !isNotElligible && __('View your channel or choose a new channel to sync.')} {isYoutubeTransferComplete && !isNotElligible && __('View your channel or choose a new channel to sync.')}
{isNotElligible && ( {isNotElligible && (

View file

@ -9,7 +9,8 @@ import { makeSelectSearchUrisForQuery, selectSearchValue } from 'redux/selectors
import handleFetchResponse from 'util/handle-fetch'; import handleFetchResponse from 'util/handle-fetch';
import { getSearchQueryString } from 'util/query-params'; import { getSearchQueryString } from 'util/query-params';
import { getRecommendationSearchOptions } from 'util/search'; import { getRecommendationSearchOptions } from 'util/search';
import { SEARCH_SERVER_API } from 'config'; import { SEARCH_SERVER_API, SEARCH_SERVER_API_ALT } from 'config';
import { SEARCH_OPTIONS } from 'constants/search';
type Dispatch = (action: any) => any; type Dispatch = (action: any) => any;
type GetState = () => { claims: any, search: SearchState }; type GetState = () => { claims: any, search: SearchState };
@ -24,13 +25,27 @@ type SearchOptions = {
let lighthouse = { let lighthouse = {
CONNECTION_STRING: SEARCH_SERVER_API, CONNECTION_STRING: SEARCH_SERVER_API,
user_id: '',
search: (queryString: string) => fetch(`${lighthouse.CONNECTION_STRING}?${queryString}`).then(handleFetchResponse), search: (queryString: string) => fetch(`${lighthouse.CONNECTION_STRING}?${queryString}`).then(handleFetchResponse),
searchRecommendations: (queryString: string) => {
if (lighthouse.user_id) {
return fetch(`${SEARCH_SERVER_API_ALT}?${queryString}${lighthouse.user_id}`).then(handleFetchResponse);
} else {
return fetch(`${SEARCH_SERVER_API_ALT}?${queryString}`).then(handleFetchResponse);
}
},
}; };
export const setSearchApi = (endpoint: string) => { export const setSearchApi = (endpoint: string) => {
lighthouse.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; lighthouse.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
}; };
export const setSearchUserId = (userId: ?string) => {
lighthouse.user_id = userId ? `&user_id=${userId}` : '';
};
export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => ( export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => (
dispatch: Dispatch, dispatch: Dispatch,
getState: GetState getState: GetState
@ -63,8 +78,11 @@ export const doSearch = (rawQuery: string, searchOptions: SearchOptions) => (
type: ACTIONS.SEARCH_START, type: ACTIONS.SEARCH_START,
}); });
lighthouse const cmd = searchOptions.hasOwnProperty(SEARCH_OPTIONS.RELATED_TO)
.search(queryWithOptions) ? lighthouse.searchRecommendations
: lighthouse.search;
cmd(queryWithOptions)
.then((data: { body: Array<{ name: string, claimId: string }>, poweredBy: string }) => { .then((data: { body: Array<{ name: string, claimId: string }>, poweredBy: string }) => {
const { body: result, poweredBy } = data; const { body: result, poweredBy } = data;
const uris = []; const uris = [];

View file

@ -5,7 +5,8 @@ import { SIMPLE_SITE } from 'config';
export default function Footer() { export default function Footer() {
useEffect(() => { useEffect(() => {
if (!window.sp) { if (!window.sp) {
document.getElementById('gdprPrivacyFooter').style.display = 'none'; const privacyFooterButton = document.getElementById('gdprPrivacyFooter');
if (privacyFooterButton) privacyFooterButton.style.display = 'none';
} }
}, []); }, []);
@ -31,7 +32,7 @@ export default function Footer() {
<Button label={__('Terms')} href="https://odysee.com/$/tos" /> <Button label={__('Terms')} href="https://odysee.com/$/tos" />
</li> </li>
<li className="footer__link"> <li className="footer__link">
<Button label={__('Privacy Policy')} href="https://odysee.com/$/privacypolicy" /> <Button label={__('Privacy Policy')} href="https://odysee.com/$/privacypolicy" />
</li> </li>
<li className="footer__link" id="gdprPrivacyFooter"> <li className="footer__link" id="gdprPrivacyFooter">
<Button label={__('Cookies')} onClick={() => window.sp && window.sp.showPrivacyBanner()} /> <Button label={__('Cookies')} onClick={() => window.sp && window.sp.showPrivacyBanner()} />