Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

413 ERROR for this type of fetch #69

Open
xanderjakeq opened this issue Jan 14, 2020 · 1 comment
Open

413 ERROR for this type of fetch #69

xanderjakeq opened this issue Jan 14, 2020 · 1 comment

Comments

@xanderjakeq
Copy link

xanderjakeq commented Jan 14, 2020

notifs = await Notification.fetchList({
            offset,
            limit,
            author: {
                $ne: username
            },
            listId: listIds,
            sort: '-createdAt'
        });

Where listIds is an array
This should fetch Notification models with listId values that are in the listIds array.

Is there a limit to how long the listIds array is?

I'm currently having a problem where it's giving me 431 error when the length of listIds array is greater than or equal to 160.

Is there a better way to query Notifications? or a workaround for this?

@xanderjakeq
Copy link
Author

This is the solution I came up with.

  1. chunk listIds to subarrays with a length shorter than 160 (I settled with 100)
  2. for each chunk, do a fetchList.
  3. flatten the result
  4. sort the flattened results
const chunked_listIds = chunk(listIds, 100);

const chunked_notifs = await Promise.all(chunked_listIds.map( async (chunk) => {
		return await Notification.fetchList({
				offset,
				limit,
				author: {
					$ne: username
				},
				listId: chunk,
				sort: '-createdAt'
			});
		}));

 const _notifs = chunked_notifs.flat();
 const notifs = _notifs.sort()

do let me know if there is a better way! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant