Skip to content

Commit

Permalink
Fix the time delay in fetching job posting (#101)
Browse files Browse the repository at this point in the history
* Changed the coptyright name to Job Bank with todo comment

* Added the vercel.json file with the max duration time

* Fixed the time response bug in fetching job posting by manually setting to sort only using the unique ids
  • Loading branch information
ama-cantabile authored May 28, 2024
1 parent 5e24460 commit a05433f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/app/api/job-posting/siteRequestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ export async function fetchJobPostings(

let query = Posting.find({ ...siteCriteria, ...filterObject });

// Check if sortCriteria is defined before sorting
// Check if sortCriteria is defined and sort by it, ensuring to include _id for uniqueness
if (sortCriteria && sortCriteria.datePosted !== undefined) {
// Ensure sortCriteria includes _id to maintain unique ordering
sortCriteria._id = 1;
query = query.sort(sortCriteria);
} else {
// Default sort by _id if no sortCriteria is provided
query = query.sort({ _id: 1 });
}
query = query.skip(skip);

const documents = await query.exec();

// Split the process and used slice instead of chaining with .limit() to avoid sorted order bug
// Todo: Investigate the bug and fix it
const paginatedDocuments = documents.slice(0, pageSize);
// Apply skip and limit for pagination
query = query.skip(skip).limit(pageSize);

return paginatedDocuments;
// Execute the query and return the results
const documents = await query.exec();
return documents;
}

// Function to check if the requested field exists in the schema
Expand Down
3 changes: 2 additions & 1 deletion src/components/jobsite/Footer.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export default function Footer() {
//Todo: Add the Business name to the coptyright
return (
<div
style={{
padding: '40px 0',
textAlign: 'center',
}}>
Copyright © Videre. All rights reserved.
Copyright © Job Bank. All rights reserved.
</div>
);
}
7 changes: 7 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"functions": {
"src/app/api/**/*": {
"maxDuration": 60
}
}
}

0 comments on commit a05433f

Please sign in to comment.