Skip to content

Commit

Permalink
Some about for offset limit
Browse files Browse the repository at this point in the history
  • Loading branch information
naari3 committed Nov 29, 2020
1 parent e8a860d commit 2368865
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/pager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const maxOffset = 1600;
export const MAX_OFFSET = 1600;

export const maxPageNumber = (per: number): number => {
return Math.ceil(maxOffset / per) + 1;
return Math.ceil(MAX_OFFSET / per) + 1;
};

export const calcPageNumber = (per: number, count: number) => {
Expand Down
9 changes: 5 additions & 4 deletions pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { format } from "date-fns";
import * as Sentry from "@sentry/node";
import { AxiosError } from "axios";

import { actualMaxPageNumber } from "../lib/pager";
import { actualMaxPageNumber, MAX_OFFSET } from "../lib/pager";

export default function Search({
videos,
Expand Down Expand Up @@ -92,9 +92,6 @@ const calcOffset = (page?: number, per: number = 100): number => {
page = 1;
}
let offset = (page - 1) * per;
if (offset > 1600) {
return 1600;
}

return offset;
};
Expand Down Expand Up @@ -290,6 +287,10 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
> => {
if (shouldExecCall(searchOptions)) {
const searchQuery = getSearchQuery(searchOptions);
if (searchQuery._offset > MAX_OFFSET) {
searchQuery._offset = 0;
searchQuery._limit = 0;
}
const response = (
await client.search(searchQuery, usedFields).catch((e: AxiosError) => {
Sentry.captureException(e);
Expand Down

0 comments on commit 2368865

Please sign in to comment.