Query Issue Pagination

Hey guys! Out of nowhere today my pagination started going haywire. Pagination is super easy and the code is good (take a look?) but somehow the UI is not displaying the results.

I have a grid container 3 boxes wide. When I query, I skip the page number - 1, times the 3 grid boxes, and then limit the results by 3. I spent many hours today trying different methods and combinations of numbers and not a single query displayed correctly.

For example, with only 6 total items in for the results length, there should be 2 pages of results each with 3 grid boxes.
Somehow page 1 renders 3 boxes with results 1-3, that is good. However page 2 only returns item 4, and somehow on page 3 (which shouldn’t exist) it displays items 5 and 6.

Page_____Amount to Skip____Items Returned______Correct?
_2_____________3_____________4_______________No, should contain 5,6
_3_____________6_____________5,6_____________No, should be empty

One example, but none work. Am I going crazy? Or do you seen something wrong that I can’t? Thanks!

Moralis.Cloud.define("renderMyProjects", async (request) => {
    const rowsSkipped = ( (request.params.page - 1) * 3);
    const currentUser = request.user;
    const relation = currentUser.relation('projects');
    const query = relation.query();
    query.select('creatorProfilePic', 'title','projectPhoto', 'summary', 'isVerified','date','description', 'creator.username', 'creator.profilePic', 'createdAt');
    const queryResults = await query.find({useMasterKey:true});
    const results = [];
    for (let i = 0; i < queryResults.length; ++i) {
        "username": queryResults[i].attributes.creator.attributes.username,
        "profilePic": queryResults[i].attributes.creator.attributes.profilePic._url,
        "title": queryResults[i].attributes.title,
        "projectPhoto": queryResults[i].attributes.projectPhoto._url,
        "summary": queryResults[i].attributes.summary,    	
        "createdOn": queryResults[i].attributes.date,
        "description": queryResults[i].attributes.description,
        'isVerified': queryResults[i].attributes.isVerified,
  return results;

Here is visually what I describe, please excuse any text/images/etc as these are just meant to be placeholders.

I tried this code and it looks to work as expected, as in returning 3 results consistently:

  const query = new Parse.Query("table_name_with_41_entries");
  rowsSkipped = 5;
  const result = await query.find();

Yeah I can’t figure out how it stopped working properly. It’s happening to other queries throughout my app as well despite all following the same scheme, q.descending(), q.skip(), q.limit().

If I change the limit to 2 per page and the skip amount to 2 per page, it does something completely different:

Page 1, items 1 and 2 display… good
Page 2, items 3 and 4 display… good
Page 3, nothing ??? should be 5 and 6
Page 4 only item 5 displays, should be empty
Page 5 only item 6 displays should be empty

I cleared the cloud functions, restarted the server, and pasted them back. Nothing. Not sure what is going on but it seems the server is giving back the wrong results

You have the same problem also with simpler queries that don’t use something like currentUser.relation?

No! The one query that I don’t use a relation on is working normally! I think you are on to something