@@ -8,8 +8,9 @@ const PLAYLIST_REVALIDATE_TIME = 60 * 60 * 24; // 24 hours
88const REVIEW_REVALIDATE_TIME = 60 * 60 * 24 ; // 24 hours
99
1010/* ---------------------------------- USERS --------------------------------- */
11+ const USER_PER_PAGE = 10000 ;
1112export const getSitemapUserCount = cache (
12- async ( perPage : number = 10000 ) : Promise < number > => {
13+ async ( perPage : number = USER_PER_PAGE ) : Promise < number > => {
1314 const supabase = await createClient ( routing . defaultLocale ) ;
1415 const { count, error } = await supabase
1516 . from ( 'profile' )
@@ -23,9 +24,8 @@ export const getSitemapUserCount = cache(
2324 } ,
2425 { revalidate : USER_REVALIDATE_TIME } ,
2526) ;
26-
2727export const getSitemapUsers = cache (
28- async ( id : number , perPage : number = 10000 ) => {
28+ async ( id : number , perPage : number = USER_PER_PAGE ) => {
2929 const start = id * perPage ;
3030 const end = start + perPage - 1 ;
3131 const supabase = await createClient ( routing . defaultLocale ) ;
@@ -34,8 +34,7 @@ export const getSitemapUsers = cache(
3434 . select ( 'id, username, created_at' )
3535 . eq ( 'private' , false )
3636 . range ( start , end )
37- . order ( 'followers_count' , { ascending : false } )
38- . order ( 'created_at' , { ascending : false } ) ;
37+ . order ( 'created_at' , { ascending : true } ) ;
3938 if ( error ) throw error ;
4039 return data || [ ] ;
4140 } ,
@@ -45,8 +44,9 @@ export const getSitemapUsers = cache(
4544
4645/* --------------------------------- MEDIAS --------------------------------- */
4746// Movies
47+ const MEDIA_MOVIE_PER_PAGE = 500 ;
4848export const getSitemapMediaMovieCount = cache (
49- async ( perPage : number = 500 ) => {
49+ async ( perPage : number = MEDIA_MOVIE_PER_PAGE ) => {
5050 const supabase = await createClient ( routing . defaultLocale ) ;
5151 const { count, error } = await supabase
5252 . from ( 'tmdb_movie' )
@@ -60,7 +60,7 @@ export const getSitemapMediaMovieCount = cache(
6060 { revalidate : MEDIA_REVALIDATE_TIME } ,
6161) ;
6262export const getSitemapMediaMovies = cache (
63- async ( id : number , perPage : number = 500 ) => {
63+ async ( id : number , perPage : number = MEDIA_MOVIE_PER_PAGE ) => {
6464 const start = id * perPage ;
6565 const end = start + perPage - 1 ;
6666 const supabase = await createClient ( routing . defaultLocale ) ;
@@ -76,16 +76,17 @@ export const getSitemapMediaMovies = cache(
7676 )
7777 ` )
7878 . range ( start , end )
79- . order ( 'popularity ' , { ascending : false } ) ;
79+ . order ( 'id ' , { ascending : true } ) ;
8080 if ( error ) throw error ;
8181 return data || [ ] ;
8282 } ,
8383 { revalidate : MEDIA_REVALIDATE_TIME } ,
8484) ;
8585
8686// TV Series
87+ const MEDIA_TV_SERIES_PER_PAGE = 500 ;
8788export const getSitemapMediaTvSeriesCount = cache (
88- async ( perPage : number = 500 ) => {
89+ async ( perPage : number = MEDIA_TV_SERIES_PER_PAGE ) => {
8990 const supabase = await createClient ( routing . defaultLocale ) ;
9091 const { count, error } = await supabase
9192 . from ( 'tmdb_tv_series' )
@@ -98,9 +99,8 @@ export const getSitemapMediaTvSeriesCount = cache(
9899 } ,
99100 { revalidate : MEDIA_REVALIDATE_TIME } ,
100101) ;
101-
102102export const getSitemapMediaTvSeries = cache (
103- async ( id : number , perPage : number = 500 ) => {
103+ async ( id : number , perPage : number = MEDIA_TV_SERIES_PER_PAGE ) => {
104104 const start = id * perPage ;
105105 const end = start + perPage - 1 ;
106106 const supabase = await createClient ( routing . defaultLocale ) ;
@@ -116,39 +116,18 @@ export const getSitemapMediaTvSeries = cache(
116116 )
117117 ` )
118118 . range ( start , end )
119- . order ( 'popularity ' , { ascending : false } ) ;
119+ . order ( 'id ' , { ascending : true } ) ;
120120 if ( error ) throw error ;
121121 return data || [ ] ;
122122 } ,
123123 { revalidate : MEDIA_REVALIDATE_TIME } ,
124124) ;
125-
126-
127- export const getSitemapMediaCount = cache (
128- async ( perPage : number = 500 ) => {
129- const supabase = await createClient ( routing . defaultLocale ) ;
130- const { count : filmCount , error : filmError } = await supabase
131- . from ( 'tmdb_movie' )
132- . select ( '*' , { count : 'exact' , head : true } ) ;
133- if ( filmError ) throw filmError ;
134- const { count : seriesCount , error : seriesError } = await supabase
135- . from ( 'tmdb_tv_series' )
136- . select ( '*' , { count : 'exact' , head : true } ) ;
137- if ( seriesError ) throw seriesError ;
138-
139- return {
140- films : filmCount ? Math . ceil ( filmCount / perPage ) : 0 ,
141- series : seriesCount ? Math . ceil ( seriesCount / perPage ) : 0 ,
142- }
143- } ,
144- { revalidate : MEDIA_REVALIDATE_TIME } ,
145- ) ;
146-
147125/* -------------------------------------------------------------------------- */
148126
149127/* -------------------------------- PLAYLISTS ------------------------------- */
128+ const PLAYLIST_PER_PAGE = 10000 ;
150129export const getSitemapPlaylistCount = cache (
151- async ( perPage : number = 10000 ) : Promise < number > => {
130+ async ( perPage : number = PLAYLIST_PER_PAGE ) : Promise < number > => {
152131 const supabase = await createClient ( routing . defaultLocale ) ;
153132 const { count, error } = await supabase
154133 . from ( 'playlists' )
@@ -163,15 +142,15 @@ export const getSitemapPlaylistCount = cache(
163142 { revalidate : PLAYLIST_REVALIDATE_TIME }
164143) ;
165144export const getSitemapPlaylists = cache (
166- async ( id : number , perPage : number = 10000 ) => {
145+ async ( id : number , perPage : number = PLAYLIST_PER_PAGE ) => {
167146 const start = id * perPage ;
168147 const end = start + perPage - 1 ;
169148 const supabase = await createClient ( routing . defaultLocale ) ;
170149 const { data, error } = await supabase
171150 . from ( 'playlists' )
172151 . select ( 'id, title, updated_at' )
173- // .eq('private', false) // RLS already handles this
174- . range ( start , end ) ;
152+ . range ( start , end )
153+ . order ( 'id' , { ascending : true } ) ;
175154 if ( error ) throw error ;
176155 return data || [ ] ;
177156 } ,
@@ -180,8 +159,9 @@ export const getSitemapPlaylists = cache(
180159/* -------------------------------------------------------------------------- */
181160
182161/* --------------------------------- REVIEWS -------------------------------- */
162+ const REVIEW_PER_PAGE = 10000 ;
183163export const getSitemapReviewMovieCount = cache (
184- async ( perPage : number = 10000 ) : Promise < number > => {
164+ async ( perPage : number = REVIEW_PER_PAGE ) : Promise < number > => {
185165 const supabase = await createClient ( routing . defaultLocale ) ;
186166 const { count, error } = await supabase
187167 . from ( 'user_reviews_movie' )
@@ -195,7 +175,7 @@ export const getSitemapReviewMovieCount = cache(
195175 { revalidate : REVIEW_REVALIDATE_TIME } ,
196176) ;
197177export const getSitemapReviewTvSeriesCount = cache (
198- async ( perPage : number = 10000 ) : Promise < number > => {
178+ async ( perPage : number = REVIEW_PER_PAGE ) : Promise < number > => {
199179 const supabase = await createClient ( routing . defaultLocale ) ;
200180 const { count, error } = await supabase
201181 . from ( 'user_reviews_tv_series' )
@@ -210,28 +190,30 @@ export const getSitemapReviewTvSeriesCount = cache(
210190) ;
211191
212192export const getSitemapReviewsMovie = cache (
213- async ( id : number , perPage : number = 10000 ) => {
193+ async ( id : number , perPage : number = REVIEW_PER_PAGE ) => {
214194 const start = id * perPage ;
215195 const end = start + perPage - 1 ;
216196 const supabase = await createClient ( routing . defaultLocale ) ;
217197 const { data, error } = await supabase
218198 . from ( 'user_reviews_movie' )
219199 . select ( 'id, updated_at, activity:user_activities_movie(movie_id)' )
220- . range ( start , end ) ;
200+ . range ( start , end )
201+ . order ( 'created_at' , { ascending : true } ) ;
221202 if ( error ) throw error ;
222203 return data || [ ] ;
223204 } ,
224205 { revalidate : REVIEW_REVALIDATE_TIME } ,
225206) ;
226207export const getSitemapReviewsTvSeries = cache (
227- async ( id : number , perPage : number = 10000 ) => {
208+ async ( id : number , perPage : number = REVIEW_PER_PAGE ) => {
228209 const start = id * perPage ;
229210 const end = start + perPage - 1 ;
230211 const supabase = await createClient ( routing . defaultLocale ) ;
231212 const { data, error } = await supabase
232213 . from ( 'user_reviews_tv_series' )
233214 . select ( 'id, updated_at, activity:user_activities_tv_series(tv_series_id)' )
234- . range ( start , end ) ;
215+ . range ( start , end )
216+ . order ( 'created_at' , { ascending : true } ) ;
235217 if ( error ) throw error ;
236218 return data || [ ] ;
237219 } ,
0 commit comments