Skip to content
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

[FEATURE] Backend Pagination #44

Open
Chmod351 opened this issue Aug 10, 2023 · 0 comments
Open

[FEATURE] Backend Pagination #44

Chmod351 opened this issue Aug 10, 2023 · 0 comments
Labels
enhancement New feature or request task this is a task to do web version this is only for web version

Comments

@Chmod351
Copy link
Owner

Feature Description

Improves Performance: When you have large amounts of data, retrieving and processing all the data at once can be costly in terms of time and resources. Pagination divides the data into smaller parts, enhancing the overall performance of your application by reducing the load on the database and server.

Use Case

API Performance: If your application serves data through an API, implementing pagination can help improve API performance by reducing the amount of data transferred in each request.
Optimizing Database Queries: Backend pagination often involves using query parameters to retrieve a specific range of data. This can lead to more efficient database queries, as you only fetch the necessary data instead of retrieving and processing the entire dataset.
Reduced Resource Consumption: By fetching and processing only a subset of data at a time, you can reduce the strain on both your server's resources and the database. This helps maintain optimal performance, prevents memory overflows, and allows your application to handle more simultaneous users

Proposed Solution

i implemented backend pagination in another project, this is the code snippet, something like this would be great, probably up to 50 results

async function getProduct(page, size) {
  // Pagination for products
  const actualPage = parseInt(page) || 1;
  const pageSize = parseInt(size) || 8;
  const skipCount = (actualPage - 1) * pageSize;
  const totalCount = await Product.countDocuments();
  const totalPages = Math.ceil(totalCount / pageSize);

  const products = await Product.aggregate([
    { $sample: { size: totalCount } },
    { $skip: skipCount },
    { $limit: pageSize },
  ]);
console.log(products);
  return { products, totalPages };
}

Expected Benefits

Faster Load Times: With pagination, users can quickly access the initial set of data without waiting for the entire dataset to load. This is especially important when dealing with mobile or web applications, where users expect fast response times.

Alternatives Considered (Optional)

i m open to anothers alternatives but i dont know any other

Additional Information

@Chmod351 Chmod351 added the enhancement New feature or request label Aug 10, 2023
@Chmod351 Chmod351 self-assigned this Aug 12, 2023
@Chmod351 Chmod351 added web version this is only for web version task this is a task to do labels Aug 12, 2023
@Chmod351 Chmod351 removed their assignment Aug 12, 2023
@Chmod351 Chmod351 added good first issue Good for newcomers and removed good first issue Good for newcomers labels Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request task this is a task to do web version this is only for web version
Projects
None yet
Development

No branches or pull requests

1 participant