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

File Field: Optimize inital field load to remove ajax #1083

Open
dhalucario opened this issue Mar 16, 2022 · 4 comments
Open

File Field: Optimize inital field load to remove ajax #1083

dhalucario opened this issue Mar 16, 2022 · 4 comments

Comments

@dhalucario
Copy link

dhalucario commented Mar 16, 2022

Version

  • Carbon Fields: 3.3.2
  • WordPress: 5.9.2
  • PHP: 7.2

Expected Behavior

The file field should load the file data as a html element property initially without an ajax request.

Actual Behavior

The file field sends 40 ajax requests when there is 40 file fields which makes no sense when you have large repeater fields.

Container definition

        // Trimmed down example
        Container::make('post_meta', __('Content', 'redacted'))
            ->where('post_type', '=', self::$postType)
            ->add_fields([
                Field::make('complex', 'redacted-dla-downloads', __('Downloads', 'redacted'))
                    ->add_fields('file', [
                        Field::make('file', 'file', __('File', 'redacted')),
                        Field::make('association', 'download_category', __('Category', 'redacted'))
                            ->set_types([
                                [ 'type' => 'term', 'taxonomy' => self::$category]
                            ]),
                        Field::make('date', 'date', __('Date', 'redacted')),
                    ])
            ]);

Steps to Reproduce the Problem

  1. Create a Container with a repeater which contains a file field.
  2. Put a lot of content into the repeater e.g 40 fields just with a file picker
  3. Save and page will take forever to load.

Comments

I tried to debug this myself but ran into dependency issues, what NodeJS version are you using for this project?
My idea is to just remove the ajax code and add necessary information to the React component using attributes. By the time the user loads the page the second time the attachment should be cached anyway and this removes setting up a new network request just to get a singular file, or 40 when there is a lot.

@dhalucario dhalucario changed the title File Field: Optimize inital field load to remove ajax. File Field: Optimize inital field load to remove ajax Mar 16, 2022
@dhalucario
Copy link
Author

dhalucario commented Mar 27, 2022

Hm I have read into the code and I see why you guys do it like this now. But I think we can cache the network request. The file shouldn't change unless someone uses a file replace plugin. But even then they can clear the cache in their browser.

@3anglepro
Copy link

Same here +

@zadro
Copy link

zadro commented Oct 12, 2023

I encountered a similar situation with over 100 requests that were additionally timing out due to Nginx limit_req rules.

In my scenario, "tabs" are used for the file structure, and each tab holds many files. Is there a way to only load the current tab and ajax request the others when clicked on?

Or, was there a further resolution to this issue by introducing caching or other means?

@henrik-dons
Copy link

Same here! Is there any way to disable the AJAX requests? Or maybe apply lazy loading?

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

No branches or pull requests

4 participants