Skip to content

Further optimize adding tasks on page load #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 22 additions & 28 deletions assets/js/suggested-task-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,35 @@ const prplTerms = {
const TermsCollection = new wp.api.collections[ typeName ]();
TermsCollection.fetch( { data: { per_page: 100 } } ).done(
( data ) => {
let userTermFound = false;
// 100 is the maximum number of terms that can be fetched in one request.
data.forEach( ( term ) => {
prplSuggestedTasksTerms[ taxonomy ][ term.slug ] =
term;
if ( 'user' === term.slug ) {
userTermFound = true;
}
} );

// If the `user` term doesn't exist, create it.
const UserTermsCollection = new wp.api.collections[
typeName
]();
UserTermsCollection.fetch( {
data: { slug: 'user' },
} )
.then( ( userTerms ) => {
if ( 0 === userTerms.length ) {
const newTermModel = new wp.api.models[
typeName
]( {
slug: 'user',
name: 'user',
} );
return newTermModel
.save()
.then( ( response ) => {
prplSuggestedTasksTerms[
taxonomy
].user = response;
return prplSuggestedTasksTerms[
taxonomy
];
} );
if ( userTermFound ) {
resolve( prplSuggestedTasksTerms[ taxonomy ] );
} else {
// If the `user` term doesn't exist, create it.
const newTermModel = new wp.api.models[ typeName ](
{
slug: 'user',
name: 'user',
}
return prplSuggestedTasksTerms[ taxonomy ];
} )
.then( resolve ); // Resolve the promise after all requests are complete.
);
newTermModel
.save()
.then( ( response ) => {
prplSuggestedTasksTerms[ taxonomy ].user =
response;
return prplSuggestedTasksTerms[ taxonomy ];
} )
.then( resolve ); // Resolve the promise after all requests are complete.
}
}
);
} );
Expand Down
Loading