If the number of records exceeds 1000 or more, the program will make an error when inline editing an

If the number of records exceeds 1000 or more, the program will make an error when inline editing an

lancwplancwp Posts: 90Questions: 20Answers: 1

Link to test case:
http://www.oceanshoes.com/temp/gborder.php

Debugger code (debug.datatables.net): staff.php

    include( "../lib/DataTables.php" );


    // Web and thumbs paths to file
      $webPath = '/uploads/233.jpg';

    // System paths
        $sysPath = $_SERVER['DOCUMENT_ROOT'] . $webPath;


    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;

    // Build our Editor instance and process the data coming from _POST


    Editor::inst( $db, 'ocorder' )

        ->fields(

            Field::inst( 'ocorder.id' )->set(false)  //ID是自新增的,加上set(false才能新增后自动刷新)
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'id is required' )   
                ) ),
            Field::inst( 'ocorder.factory' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( '大底工厂不能为空' ) 
                ) ),                        

            Field::inst( 'ocorder.ddbh' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( '大底编号不能为空' ) 
                ) )
            ,               
            Field::inst( 'ocorder.type1' )
                     ->setFormatter( Format::ifEmpty( null ) ),
            Field::inst( 'ocorder.size' ),          
            Field::inst( 'ocorder.sizediff' ),          

        Field::inst( 'ocorder.type2' )
                ->options( Options::inst()
                    ->table( 'serviceshow4' )
                    ->value( 'name' )
                    ->label( 'name' )
                ),  

       Field::inst( 'ocorder.type3' ),
        Field::inst( 'serviceshow4.name2' ),




         Field::inst( 'ocorder.keyword' ),      
         Field::inst( 'ocorder.istax' ),
         Field::inst( 'ocorder.wear' ), 
         Field::inst( 'ocorder.bjbz' ),
         Field::inst( 'ocorder.bjstau' ),           


    //    ->upload( Upload::inst('//10.0.8.7'.'/uploads/__ID__.__EXTN__' )              

        Field::inst( 'ocorder.hppic' )
         ->setFormatter( Format::ifEmpty( null ) )
        ->upload(
            Upload::inst( function ( $file, $id ) use ( $db ) {
            $extn = pathinfo( $file['name'], PATHINFO_EXTENSION ); // get extension
             $systempath=$_SERVER['DOCUMENT_ROOT'].'/uploads/'.$id.".".$extn;
             $sysPathThumbs1=$_SERVER['DOCUMENT_ROOT'].'/uploads/'.$id."_small".".".$extn;
             $webpath='/uploads/'.$id.".".$extn;  
             $webPathTumbs1='/uploads/'.$id."_small".".".$extn; 
            move_uploaded_file( $file['tmp_name'], $systempath);            
            createSmall($systempath);


           $db->update(
              'files',array(
              'web_path'    => $webpath,
               'webPathTumbs1'    => $webPathTumbs1,
              'system_path' => $systempath,
               'sysPathThumbs1' => $sysPathThumbs1
               ),
               array( 'ID' => $id )
               );
                return $id;
             } )

                ->db( 'files', 'id', array(
                    'fileName' => Upload::DB_FILE_NAME,
                    'fileSize' => Upload::DB_FILE_SIZE,
                    'web_path' => '',
                    'webPathTumbs1' => '',
                        'system_path' => '',
                        'sysPathThumbs1' => ''

                      ) )

             ->dbClean( function ( $data ) {
                    // Remove the files from the file system
                    for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
                        unlink( $data[$i]['system_path'] );
                    }
                 return true;
                } ) 

             ->validator( Validate::fileSize( 500000, '图片大小不能超过500K' ) )
                    ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )   

              ),






                Field::inst( 'ocorder.hppic2' )
         ->setFormatter( Format::ifEmpty( null ) )
        ->upload(
            Upload::inst( function ( $file, $id ) use ( $db ) {
            $extn = pathinfo( $file['name'], PATHINFO_EXTENSION ); // get extension
             $systempath=$_SERVER['DOCUMENT_ROOT'].'/uploads/'.$id.".".$extn;
             $sysPathThumbs1=$_SERVER['DOCUMENT_ROOT'].'/uploads/'.$id."_small".".".$extn;
             $webpath='/uploads/'.$id.".".$extn;  
             $webPathTumbs1='/uploads/'.$id."_small".".".$extn; 
            move_uploaded_file( $file['tmp_name'], $systempath);            
            createSmall($systempath);


           $db->update(
              'files2',array(
              'web_path'    => $webpath,
               'webPathTumbs1'    => $webPathTumbs1,
              'system_path' => $systempath,
               'sysPathThumbs1' => $sysPathThumbs1
               ),
               array( 'ID' => $id )
               );
                return $id;
             } )

                ->db( 'files2', 'id', array(
                    'fileName' => Upload::DB_FILE_NAME,
                    'fileSize' => Upload::DB_FILE_SIZE,
                    'web_path' => '',
                    'webPathTumbs1' => '',
                        'system_path' => '',
                        'sysPathThumbs1' => ''

                      ) )

             ->dbClean( function ( $data ) {
                    // Remove the files from the file system
                    for ( $i=0, $ien=count($data) ; $i<$ien ; $i++ ) {
                        unlink( $data[$i]['system_path'] );
                    }
                 return true;
                } ) 

             ->validator( Validate::fileSize( 500000, '图片大小不能超过500K' ) )
                    ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )   

              ),






            Field::inst( 'ocorder.content1' )
             ->setFormatter( Format::ifEmpty( null ) ),

            Field::inst( 'ocorder.removed_date' )
                ->setFormatter( Format::ifEmpty( null ) )

        )

    ->on( 'preCreate', function ( $editor, &$values ) {       


        } )

         ->on( 'preEdit', function ( $editor, $id, &$values ) {


        } )


        ->leftJoin( 'serviceshow4',   'ocorder.type2',   '=', 'serviceshow4.name' )
        ->where( 'ocorder.removed_date', null )
    ->on( 'preRemove', function () {
            // Disallow all delete actions since data cannot be removed completely
            return false;
        } )



        ->debug(true)
        ->process( $_POST )
        ->json();

Error messages shown:

Description of problem:

Inline editing and two field linkage. If the number of records exceeds 1000 or more, the program will make an error. If modifications are made, an error will occur and it will be saved, but it is slow. If everything is normal and there is no error like the current 717 records

I found that when there are few normal records, the output JSON value at the end contains "bindings":[

{

"name": ":wherein1",

"value": "19230211",

"type": null

}

When there are many records, the bindings become empty

I don't know where the problem lies, can you assist me

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    What is the response from the server when the error happens? Or can you update your page to have >10k records?

    Allan

  • lancwplancwp Posts: 90Questions: 20Answers: 1
    edited May 2023

    I have updated and now there are 9683 records,
    At this point, if any of the fields inside are modified, the table will become very slow, and it will take a long time for the currently modified cells to report an error. Is there a problem with the JSON format of the output, which is used in conjunction

    editor.dependent( 'ocorder.type2', 'controllers/countries2.php' );

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Many thanks.

    The server is timing out for some reason. If you comment out the ->dbClean(...) call - does that allow it to work at a reasonable speed again?

    Allan

  • lancwplancwp Posts: 90Questions: 20Answers: 1
    edited May 2023

    Yes, if hidden, it will become very fast. Is this used to delete images?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Yes - it is used to check if there are any files which are no longer referenced after an edit. And if not, then it will clean them up (typically that means to remove them from the file system and the database).

    Thanks for letting me know that addresses the speed issue - I'll look into options to improve the speed there. It certainly shouldn't be causing the massive hit that it was.

    Allan

  • lancwplancwp Posts: 90Questions: 20Answers: 1

    Would it be faster to delete files for the current record to be deleted? No need to search the entire database

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Yes. It needs to capture an edit as well, or the case where a user uploads a file and then cancels the edit. That was the key reason why it isn't just on the row being edited / deleted.

    I'm certain there is more speed to getting from it though!

    Allan

Sign In or Register to comment.