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

@uppy/core: make getObjectOfFilesPerState more efficient #5155

Merged
merged 2 commits into from
May 8, 2024

Conversation

Murderlon
Copy link
Member

Only one loop instead of many. Ideally we'd have better state management in general, but that's a bigger thing. Tiny improvement for now.

@Murderlon Murderlon requested review from mifi and aduh95 May 8, 2024 12:51
@Murderlon Murderlon self-assigned this May 8, 2024
Copy link
Contributor

github-actions bot commented May 8, 2024

Diff output files
diff --git a/packages/@uppy/core/lib/Uppy.js b/packages/@uppy/core/lib/Uppy.js
index 7ec8f0f..83a1b27 100644
--- a/packages/@uppy/core/lib/Uppy.js
+++ b/packages/@uppy/core/lib/Uppy.js
@@ -417,22 +417,47 @@ export class Uppy {
       error,
     } = this.getState();
     const files = Object.values(filesObject);
-    const inProgressFiles = files.filter(_ref2 => {
-      let {
+    const inProgressFiles = [];
+    const newFiles = [];
+    const startedFiles = [];
+    const uploadStartedFiles = [];
+    const pausedFiles = [];
+    const completeFiles = [];
+    const erroredFiles = [];
+    const inProgressNotPausedFiles = [];
+    const processingFiles = [];
+    for (const file of files) {
+      const {
         progress,
-      } = _ref2;
-      return !progress.uploadComplete && progress.uploadStarted;
-    });
-    const newFiles = files.filter(file => !file.progress.uploadStarted);
-    const startedFiles = files.filter(file =>
-      file.progress.uploadStarted || file.progress.preprocess || file.progress.postprocess
-    );
-    const uploadStartedFiles = files.filter(file => file.progress.uploadStarted);
-    const pausedFiles = files.filter(file => file.isPaused);
-    const completeFiles = files.filter(file => file.progress.uploadComplete);
-    const erroredFiles = files.filter(file => file.error);
-    const inProgressNotPausedFiles = inProgressFiles.filter(file => !file.isPaused);
-    const processingFiles = files.filter(file => file.progress.preprocess || file.progress.postprocess);
+      } = file;
+      if (!progress.uploadComplete && progress.uploadStarted) {
+        inProgressFiles.push(file);
+        if (!file.isPaused) {
+          inProgressNotPausedFiles.push(file);
+        }
+      }
+      if (!progress.uploadStarted) {
+        newFiles.push(file);
+      }
+      if (progress.uploadStarted || progress.preprocess || progress.postprocess) {
+        startedFiles.push(file);
+      }
+      if (progress.uploadStarted) {
+        uploadStartedFiles.push(file);
+      }
+      if (file.isPaused) {
+        pausedFiles.push(file);
+      }
+      if (progress.uploadComplete) {
+        completeFiles.push(file);
+      }
+      if (file.error) {
+        erroredFiles.push(file);
+      }
+      if (progress.preprocess || progress.postprocess) {
+        processingFiles.push(file);
+      }
+    }
     return {
       newFiles,
       startedFiles,
@@ -1030,11 +1055,11 @@ function _informAndEmit2(errors) {
   const maxNumToShow = 4;
   const firstErrors = userFacingErrors.slice(0, maxNumToShow);
   const additionalErrors = userFacingErrors.slice(maxNumToShow);
-  firstErrors.forEach(_ref3 => {
+  firstErrors.forEach(_ref2 => {
     let {
       message,
       details = "",
-    } = _ref3;
+    } = _ref2;
     this.info(
       {
         message,

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad for readability, but I get why we'd want to do that

@Murderlon Murderlon merged commit e9ccb94 into main May 8, 2024
17 checks passed
@Murderlon Murderlon deleted the getObjectOfFilesPerState branch May 8, 2024 13:43
github-actions bot added a commit that referenced this pull request May 14, 2024
| Package            | Version | Package            | Version |
| ------------------ | ------- | ------------------ | ------- |
| @uppy/core         |  3.11.3 | uppy               |  3.25.3 |
| @uppy/image-editor |   2.4.6 |                    |         |

- @uppy/image-editor: fix tooltips (Avneet Singh Malhotra / #5156)
- meta: Remove redundant `plugins` prop from examples (Merlijn Vos / #5145)
- @uppy/image-editor: Remove `target` option from examples and document consistently (Merlijn Vos / #5146)
- @uppy/core: make getObjectOfFilesPerState more efficient (Merlijn Vos / #5155)
Murderlon added a commit that referenced this pull request May 14, 2024
* commit '86e2e6750192055bfba24abf62e227976be5e085':
  Release: [email protected] (#5161)
  @uppy/image-editor: fix tooltips (#5156)
  Remove redundant `plugins` prop from examples (#5145)
  Remove `target` option from examples and document consistently (#5146)
  @uppy/core: make getObjectOfFilesPerState more efficient (#5155)
  Release: [email protected] (#5151)
  Upgrade @transloadit/prettier-bytes (#5150)
github-actions bot added a commit that referenced this pull request May 14, 2024
| Package                |      Version | Package                |      Version |
| ---------------------- | ------------ | ---------------------- | ------------ |
| @uppy/companion        | 5.0.0-beta.6 | @uppy/status-bar       | 4.0.0-beta.7 |
| @uppy/companion-client | 4.0.0-beta.6 | @uppy/unsplash         | 4.0.0-beta.6 |
| @uppy/compressor       | 2.0.0-beta.7 | @uppy/url              | 4.0.0-beta.6 |
| @uppy/core             | 4.0.0-beta.7 | @uppy/utils            | 6.0.0-beta.6 |
| @uppy/dashboard        | 4.0.0-beta.7 | @uppy/webcam           | 4.0.0-beta.6 |
| @uppy/dropbox          | 4.0.0-beta.6 | @uppy/xhr-upload       | 4.0.0-beta.4 |
| @uppy/image-editor     | 3.0.0-beta.4 | uppy                   | 4.0.0-beta.7 |
| @uppy/screen-capture   | 4.0.0-beta.5 |                        |              |

- @uppy/companion: switch from `node-redis` to `ioredis` (Dominik Schmidt / #4623)
- meta: Fix headings in xhr.mdx (Merlijn Vos)
- @uppy/xhr-upload: introduce hooks similar to tus (Merlijn Vos / #5094)
- @uppy/core: close->destroy, clearUploadedFiles->clear (Merlijn Vos / #5154)
- @uppy/companion-client,@uppy/dropbox,@uppy/screen-capture,@uppy/unsplash,@uppy/url,@uppy/webcam: Use `title` consistently from locales (Merlijn Vos / #5134)




| Package            | Version | Package            | Version |
| ------------------ | ------- | ------------------ | ------- |
| @uppy/core         |  3.11.3 | uppy               |  3.25.3 |
| @uppy/image-editor |   2.4.6 |                    |         |

- @uppy/image-editor: fix tooltips (Avneet Singh Malhotra / #5156)
- meta: Remove redundant `plugins` prop from examples (Merlijn Vos / #5145)
- @uppy/image-editor: Remove `target` option from examples and document consistently (Merlijn Vos / #5146)
- @uppy/core: make getObjectOfFilesPerState more efficient (Merlijn Vos / #5155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants