@@ -36,17 +36,12 @@ const generateUrlAliases = async (params: GenerateParams): Promise<number> => {
3636
3737 let relations : string [ ] = [ ] ;
3838
39- const locales = await strapi . documents ( 'plugin::i18n.locale' ) . findMany ( { } ) ;
40- const languages = locales . map ( ( locale ) => locale . code ) ;
41-
42- // Get all relations for the type
43- await Promise . all ( languages . map ( async ( lang ) => {
44- const urlPatterns = await getPluginService ( 'url-pattern' ) . findByUid ( type , lang ) ;
45- urlPatterns . forEach ( ( urlPattern ) => {
46- const languageRelations = getPluginService ( 'url-pattern' ) . getRelationsFromPattern ( urlPattern ) ;
47- relations = [ ...relations , ...languageRelations ] ;
48- } ) ;
49- } ) ) ;
39+ // Get all relations for the type from all patterns for all languages.
40+ const urlPatterns = await getPluginService ( 'url-pattern' ) . findByUid ( type ) ;
41+ urlPatterns . forEach ( ( urlPattern ) => {
42+ const languageRelations = getPluginService ( 'url-pattern' ) . getRelationsFromPattern ( urlPattern ) ;
43+ relations = [ ...relations , ...languageRelations ] ;
44+ } ) ;
5045
5146 // Query all the entities of the type that do not have a corresponding URL alias.
5247 const entities = await strapi . documents ( type as 'api::test.test' ) . findMany ( {
@@ -70,9 +65,10 @@ const generateUrlAliases = async (params: GenerateParams): Promise<number> => {
7065 */
7166 // eslint-disable-next-line no-restricted-syntax
7267 for ( const entity of entities ) {
68+ // FIXME: just filter the `urlPatterns` we already have.
7369 // eslint-disable-next-line no-await-in-loop
74- const urlPatterns = await getPluginService ( 'url-pattern' ) . findByUid ( type , entity . locale ) ;
75- const resolvedPath = getPluginService ( 'url-pattern' ) . resolvePattern ( type , entity , urlPatterns [ 0 ] ) ;
70+ const entityUrlPatterns = await getPluginService ( 'url-pattern' ) . findByUid ( type , entity . locale ) ;
71+ const resolvedPath = getPluginService ( 'url-pattern' ) . resolvePattern ( type , entity , entityUrlPatterns [ 0 ] ) ;
7672
7773 // eslint-disable-next-line no-await-in-loop
7874 const newUrlAlias = await strapi . documents ( 'plugin::webtools.url-alias' ) . create ( {
0 commit comments