apify-client 3.0.0-beta.85 → 3.0.0-beta.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { minForLimitParam, SCANNED_COUNT, toPath, toPathSegment } from '../utils.js';
1
+ import { minForLimitParam, toPath, toPathSegment } from '../utils.js';
2
2
  /** @private */
3
3
  export class ApiClient {
4
4
  id;
@@ -60,14 +60,14 @@ export class ApiClient {
60
60
  const { chunkSize, ...listOptions } = options;
61
61
  const firstPageLimit = minForLimitParam(options.limit, chunkSize);
62
62
  const paginatedListPromise = getPaginatedList({ ...listOptions, limit: firstPageLimit });
63
- // A page can return more or fewer items than the rows it scanned (see `SCANNED_COUNT`). The next offset and
64
- // the stop condition follow the scanned rows: advancing by `items.length` would re-scan rows after a filter
65
- // dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page would end the
66
- // iteration in front of rows a filter hid. The scanned number is derived from a dataset's item count, which
67
- // lags a fresh push, so the larger of it and `items.length` is taken, capped at the rows the request asked for
68
- // so that an unwound page does not advance past rows the next request would then never read.
63
+ // A page of dataset items can return more or fewer items than the rows it scanned (see `PaginatedList.count`).
64
+ // The next offset and the stop condition follow the scanned rows: advancing by `items.length` would re-scan
65
+ // rows after a filter dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page
66
+ // would end the iteration in front of rows a filter hid. The step is the larger of `count` and `items.length`,
67
+ // capped at the rows the request asked for, which keeps an unwound page from advancing past rows the next
68
+ // request would then never read.
69
69
  const scannedRows = (page, requestedLimit) => {
70
- const scanned = Math.max(page[SCANNED_COUNT] ?? 0, page.items.length);
70
+ const scanned = Math.max(page.count ?? 0, page.items.length);
71
71
  return requestedLimit ? Math.min(scanned, requestedLimit) : scanned;
72
72
  };
73
73
  // `total` is not consulted, as it changes when the listed resource grows during the iteration.
@@ -102,7 +102,7 @@ export class ResourceClient extends ApiClient {
102
102
  const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
103
103
  return !hasJobEnded;
104
104
  };
105
- do {
105
+ while (true) {
106
106
  const millisSinceStart = Date.now() - startedAt;
107
107
  const remainingWaitSeconds = Math.round((waitMillis - millisSinceStart) / 1000);
108
108
  const waitForFinish = Math.max(0, remainingWaitSeconds);
@@ -124,13 +124,13 @@ export class ResourceClient extends ApiClient {
124
124
  notFoundSince ??= Date.now();
125
125
  notFoundError = err;
126
126
  }
127
- // It might take some time for database replicas to get up-to-date,
128
- // so getRun() might return null. Wait a little bit and try it again.
129
- if (!job) {
130
- await sleep(250, signal);
131
- signal?.throwIfAborted();
132
- }
133
- } while (shouldRepeat());
127
+ if (!shouldRepeat())
128
+ break;
129
+ // The API answers right away when the remaining wait rounds to 0 seconds, and database replicas may not see
130
+ // a new job for a short while, so pause before the next poll.
131
+ await sleep(250, signal);
132
+ signal?.throwIfAborted();
133
+ }
134
134
  if (!job)
135
135
  throw notFoundError;
136
136
  return job;