The newer version, there might be remove() or removeFile() methods?

The newer version, there might be remove() or removeFile() methods?

lancwplancwp Posts: 103Questions: 23Answers: 1

Link to test case:

->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;
} )

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

The original code for deleting images uses dbclear, which searches through the entire image library and slows down the table performance significantly. I heard that in the newer version, there might be remove() or removeFile() methods. I have downloaded the latest version, but both methods are not recognized and indeed, I couldn't find them. How should I improve this?

Answers

  • lancwplancwp Posts: 103Questions: 23Answers: 1
    Field::inst( '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;
         $webpath='/uploads/'.$id.".".$extn;                 
        move_uploaded_file( $file['tmp_name'], $systempath);            
    
    
    
       $db->update(
          'files',array(
          'web_path'    => $webpath,
          'system_path' => $systempath
           ),
           array( 'ID' => $id )
           );
            return $id;
         } )
    
            ->db( 'files', 'id', array(
                'fileName' => Upload::DB_FILE_NAME,
                'fileSize' => Upload::DB_FILE_SIZE,
                'web_path' => '',
                    'system_path' => ''
    
                  ) )
    
         ->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" ) )   
    
          ),
    
  • lancwplancwp Posts: 103Questions: 23Answers: 1

    Actually, I only want to delete the images that have been marked for deletion or have been modified.

  • allanallan Posts: 64,301Questions: 1Answers: 10,618 Site admin

    I heard that in the newer version, there might be remove() or removeFile() methods.

    Can I ask where you heard or read that? They aren't methods that I immediately recognize.

    dbClean should only run over the files that need to be deleted from the file system (i.e. the files which don't have a reference). If there are no files to delete, then it won't run. If there is only one file to delete, the loop should only happen once. Can you clarify a bit what you mean by:

    which searches through the entire image library and slows down the table performance significantly

    Thanks,
    Allan

  • lancwplancwp Posts: 103Questions: 23Answers: 1

    Deepseek's AI told me that these two methods are available in the new version, but even after downloading the latest version, they are still not present. I believe DBCLEAR searches through all the records of the image library. I have over 7,000 records, and every time this command is executed, it takes about 30 seconds. Removing this image deletion makes the process much faster. Are there any other solutions? My goal is to delete the corresponding images when records are deleted, and to delete old images when new ones are updated, so as to avoid redundant image files remaining on the disk.

  • lancwplancwp Posts: 103Questions: 23Answers: 1

    There are quite a number of records, so the process is very slow. I am currently rewriting it. Everything else works fine, but the DBCLEA method causes the data output to be very sluggish whenever it is used.

  • allanallan Posts: 64,301Questions: 1Answers: 10,618 Site admin

    Deepseek's AI told me that these two methods are available in the new version, but even after downloading the latest version, they are still not present.

    Haha! No, they wouldn't be as there are no such method in the library at this time. Trust the docs, not the AI that makes things up ;).

    Can you add ->debug(true) immediately before the ->process(...) call please? Then perform an action that is causing things to slow down and show me the response from the server?

    Thanks,
    Allan

  • lancwplancwp Posts: 103Questions: 23Answers: 1

    In order to speed up the loading, I used serverSide: true. However, whenever the DBCLEA method was used, it became very slow and unresponsive. Everything worked fine and quickly once I removed this method. Below is a screenshot of when the method was in use, and there were also error messages.
    !

  • lancwplancwp Posts: 103Questions: 23Answers: 1
    edited April 1

    a

  • allanallan Posts: 64,301Questions: 1Answers: 10,618 Site admin

    Could you show me the JSON response and also the data submission from one of the slow requests please? Or even better, if you can give me a link to the page in question, that would hopefully let me get a better idea of what is happening.

    Allan

Sign In or Register to comment.