mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Only fetching headlines if requested to speed up RPi responses.g
This commit is contained in:
parent
8faac3f3a1
commit
bba6a341b7
12 changed files with 80 additions and 38 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import {API_URI, ARCHIVES_API, DEFAULT_LIMIT, emptyToNull, OTP_API, VIDEOS_API} from "./components/Common";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {computeHeadingLevel} from "@testing-library/react";
|
||||
|
||||
function timeoutPromise(ms, promise) {
|
||||
// Create a timeout wrapper around a promise. If the timeout is reached, throw an error. Otherwise, return
|
||||
|
|
@ -103,7 +104,7 @@ export async function getChannel(id) {
|
|||
return (await response.json())['channel'];
|
||||
}
|
||||
|
||||
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames) {
|
||||
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline) {
|
||||
// Build a search query to retrieve a list of videos from the API
|
||||
offset = parseInt(offset || 0);
|
||||
limit = parseInt(limit || DEFAULT_LIMIT);
|
||||
|
|
@ -118,6 +119,9 @@ export async function searchVideos(offset, limit, channelId, searchStr, order_by
|
|||
if (tagNames) {
|
||||
body['tag_names'] = tagNames;
|
||||
}
|
||||
if (headline) {
|
||||
body['headline'] = true;
|
||||
}
|
||||
|
||||
console.debug('searching videos', body);
|
||||
|
||||
|
|
@ -350,7 +354,7 @@ export async function deleteArchives(archiveIds) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames) {
|
||||
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline) {
|
||||
// Build a search query to retrieve a list of videos from the API
|
||||
offset = parseInt(offset || 0);
|
||||
limit = parseInt(limit || DEFAULT_LIMIT);
|
||||
|
|
@ -367,6 +371,9 @@ export async function searchArchives(offset, limit, domain, searchStr, order, ta
|
|||
if (tagNames) {
|
||||
body['tag_names'] = tagNames;
|
||||
}
|
||||
if (headline) {
|
||||
body['headline'] = true;
|
||||
}
|
||||
|
||||
console.debug('searching archives', body);
|
||||
let response = await apiPost(`${ARCHIVES_API}/search`, body);
|
||||
|
|
@ -479,7 +486,7 @@ export async function deleteDownload(downloadId) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames) {
|
||||
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline) {
|
||||
const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit)};
|
||||
if (mimetypes) {
|
||||
body['mimetypes'] = mimetypes;
|
||||
|
|
@ -490,6 +497,9 @@ export async function filesSearch(offset, limit, searchStr, mimetypes, model, ta
|
|||
if (tagNames) {
|
||||
body['tag_names'] = tagNames;
|
||||
}
|
||||
if (headline) {
|
||||
body['headline'] = true;
|
||||
}
|
||||
console.debug('searching files', body);
|
||||
const response = await apiPost(`${API_URI}/files/search`, body);
|
||||
|
||||
|
|
|
|||
|
|
@ -76,25 +76,24 @@ export const Headlines = ({results}) => {
|
|||
return <Segment>No results!</Segment>
|
||||
}
|
||||
|
||||
let items = [];
|
||||
let headlines = [];
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
const result = results[i];
|
||||
const {model, data, video} = result;
|
||||
|
||||
if (model === 'video' && !_.isEmpty(video)) {
|
||||
let video_url = `/videos/video/${video.id}`;
|
||||
const channel = video.channel ? video.channel : null;
|
||||
if (channel) {
|
||||
video_url = `/videos/channel/${channel.id}/video/${video.id}`;
|
||||
}
|
||||
items = [...items, <FileHeadline key={result['key']} file={result} to={video_url}/>];
|
||||
const {channel} = video;
|
||||
const video_url = channel
|
||||
? `/videos/channel/${channel.id}/video/${video.id}`
|
||||
: `/videos/video/${video.id}`;
|
||||
headlines = [...headlines, <FileHeadline key={result['key']} file={result} to={video_url}/>];
|
||||
} else if (model === 'archive' && !_.isEmpty(data)) {
|
||||
items = [...items, <FileHeadline key={result['key']} file={result} to={`/archive/${data.id}`}/>];
|
||||
headlines = [...headlines, <FileHeadline key={result['key']} file={result} to={`/archive/${data.id}`}/>];
|
||||
} else {
|
||||
items = [...items, <FileHeadline key={result['key']} file={result}/>];
|
||||
headlines = [...headlines, <FileHeadline key={result['key']} file={result}/>];
|
||||
}
|
||||
}
|
||||
return <>
|
||||
{items}
|
||||
{headlines}
|
||||
</>
|
||||
}
|
||||
|
|
@ -172,6 +172,8 @@ export const useSearchArchives = (defaultLimit) => {
|
|||
const searchStr = searchParams.get('q') || '';
|
||||
const order = searchParams.get('order');
|
||||
const activeTags = searchParams.getAll('tag');
|
||||
const {view} = useSearchView();
|
||||
const headline = view === 'headline';
|
||||
|
||||
const [archives, setArchives] = useState(null);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
|
|
@ -180,7 +182,7 @@ export const useSearchArchives = (defaultLimit) => {
|
|||
setArchives(null);
|
||||
setTotalPages(0);
|
||||
try {
|
||||
let [archives_, total] = await searchArchives(offset, limit, domain, searchStr, order, activeTags);
|
||||
let [archives_, total] = await searchArchives(offset, limit, domain, searchStr, order, activeTags, headline);
|
||||
setArchives(archives_);
|
||||
setTotalPages(calculateTotalPages(total, limit));
|
||||
} catch (e) {
|
||||
|
|
@ -197,7 +199,7 @@ export const useSearchArchives = (defaultLimit) => {
|
|||
|
||||
useEffect(() => {
|
||||
localSearchArchives();
|
||||
}, [searchStr, limit, domain, order, activePage, JSON.stringify(activeTags)]);
|
||||
}, [searchStr, limit, domain, order, activePage, JSON.stringify(activeTags), headline]);
|
||||
|
||||
const setSearchStr = (value) => {
|
||||
updateQuery({q: value, o: 0, order: undefined});
|
||||
|
|
@ -230,6 +232,8 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
|
|||
const searchStr = searchParams.get('q') || '';
|
||||
const order = searchParams.get('order') || order_by;
|
||||
const activeTags = searchParams.getAll('tag');
|
||||
const {view} = useSearchView();
|
||||
const headline = view === 'headline';
|
||||
|
||||
const [videos, setVideos] = useState();
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
|
|
@ -238,7 +242,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
|
|||
setVideos(null);
|
||||
setTotalPages(0);
|
||||
try {
|
||||
let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags);
|
||||
let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline);
|
||||
setVideos(videos_);
|
||||
setTotalPages(calculateTotalPages(total, limit));
|
||||
} catch (e) {
|
||||
|
|
@ -255,7 +259,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => {
|
|||
|
||||
useEffect(() => {
|
||||
localSearchVideos();
|
||||
}, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags)]);
|
||||
}, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags), headline]);
|
||||
|
||||
const setSearchStr = (value) => {
|
||||
updateQuery({q: value, o: 0, order: undefined});
|
||||
|
|
@ -404,10 +408,12 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
const filter = searchParams.get('filter');
|
||||
const model_ = searchParams.get('model');
|
||||
const activeTags = searchParams.getAll('tag');
|
||||
const {view} = useSearchView();
|
||||
|
||||
const [searchFiles, setSearchFiles] = useState(null);
|
||||
const [totalPages, setTotalPages] = useState(0);
|
||||
const [activePage, setActivePage] = useState(calculatePage(offset, limit));
|
||||
const headline = view === 'headline';
|
||||
|
||||
const localSearchFiles = async () => {
|
||||
if (!emptySearch && !searchStr && !activeTags) {
|
||||
|
|
@ -418,7 +424,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
setTotalPages(0);
|
||||
try {
|
||||
let [file_groups, total] = await filesSearch(
|
||||
offset, limit, searchStr, mimetypes, model || model_, activeTags);
|
||||
offset, limit, searchStr, mimetypes, model || model_, activeTags, headline);
|
||||
setSearchFiles(file_groups);
|
||||
setTotalPages(calculateTotalPages(total, limit));
|
||||
} catch (e) {
|
||||
|
|
@ -434,7 +440,7 @@ export const useSearchFiles = (defaultLimit = 48, emptySearch = false, model) =>
|
|||
|
||||
useEffect(() => {
|
||||
localSearchFiles();
|
||||
}, [searchStr, limit, offset, activePage, filter, model, model_, JSON.stringify(activeTags)]);
|
||||
}, [searchStr, limit, offset, activePage, filter, model, model_, JSON.stringify(activeTags), headline]);
|
||||
|
||||
const setPage = (i) => {
|
||||
i = parseInt(i);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue