久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <small id='lpagO'></small><noframes id='lpagO'>

    2. <i id='lpagO'><tr id='lpagO'><dt id='lpagO'><q id='lpagO'><span id='lpagO'><b id='lpagO'><form id='lpagO'><ins id='lpagO'></ins><ul id='lpagO'></ul><sub id='lpagO'></sub></form><legend id='lpagO'></legend><bdo id='lpagO'><pre id='lpagO'><center id='lpagO'></center></pre></bdo></b><th id='lpagO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lpagO'><tfoot id='lpagO'></tfoot><dl id='lpagO'><fieldset id='lpagO'></fieldset></dl></div>
    3. <legend id='lpagO'><style id='lpagO'><dir id='lpagO'><q id='lpagO'></q></dir></style></legend>

        <bdo id='lpagO'></bdo><ul id='lpagO'></ul>

      1. <tfoot id='lpagO'></tfoot>

        Laravel 塊和刪除

        Laravel chunk and delete(Laravel 塊和刪除)

        • <bdo id='Jpvr7'></bdo><ul id='Jpvr7'></ul>

          • <small id='Jpvr7'></small><noframes id='Jpvr7'>

          • <legend id='Jpvr7'><style id='Jpvr7'><dir id='Jpvr7'><q id='Jpvr7'></q></dir></style></legend>
            • <tfoot id='Jpvr7'></tfoot>
              <i id='Jpvr7'><tr id='Jpvr7'><dt id='Jpvr7'><q id='Jpvr7'><span id='Jpvr7'><b id='Jpvr7'><form id='Jpvr7'><ins id='Jpvr7'></ins><ul id='Jpvr7'></ul><sub id='Jpvr7'></sub></form><legend id='Jpvr7'></legend><bdo id='Jpvr7'><pre id='Jpvr7'><center id='Jpvr7'></center></pre></bdo></b><th id='Jpvr7'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Jpvr7'><tfoot id='Jpvr7'></tfoot><dl id='Jpvr7'><fieldset id='Jpvr7'></fieldset></dl></div>

                  <tbody id='Jpvr7'></tbody>
                1. 本文介紹了Laravel 塊和刪除的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想從數(shù)據(jù)庫中刪除大量項目(1M+),我分叉了一個后臺作業(yè)來處理這個問題,這樣用戶就不必等待它完成繼續(xù)無論他/她在做什么,問題是,當項目被刪除時,應用程序變得沒有響應,所以我想我會一個塊一個塊地處理這些項目,然后休眠幾秒鐘,然后繼續(xù).

                  I have a large number of items (1M+) that i want to delete from a database, i fork a background job to take care of that, so that the user won't have to wait for it to finish to carry on whatever he/she was doing, the problem is, the app becomes unresponsive while the items are being deleted, so i thought that i would process the items chunk by chunk and sleep for a couple of seconds then carry on.

                  這是處理刪除的代碼:

                  // laravel job class
                  // ...
                  public function handle()
                  {
                      $posts_archive = PostArchive::find(1); // just for the purpose of testing ;)
                      Post::where('arch_id', $posts_archive->id)->chunk(1000, function ($posts) {
                          //go through the collection and delete every post.
                          foreach($posts as $post) {
                              $post->delete();
                          }
                          // throttle
                          sleep(2);
                      });
                  }
                  

                  預期結(jié)果:帖子被分塊并處理每個塊,然后空閑 2 秒,重復此操作,直到所有項目都被刪除.

                  Expected result: the posts are chunked and each chunk is processed, then idle for 2 seconds, repeat that until all the items are deleted.

                  實際結(jié)果:隨機刪除一次,過程結(jié)束.沒有錯誤沒有指標,沒有線索?

                  Actual result: a random number of items is deleted once, then the process ends. no errors no indicators, no clue ?

                  有沒有更好的方法來實現(xiàn)這一點?

                  is there a better way to implement this?

                  推薦答案

                  Laravel 并沒有針對您處理此問題的方式進行具體說明.如果作業(yè)中的刪除查詢凍結(jié)了 UI 的其余部分,聽起來您的數(shù)據(jù)庫服務器需要審查或優(yōu)化.

                  There is nothing Laravel specific about the way you'd handle this. It sounds like your database server needs review or optimization if a delete query in a job is freezing the rest of the UI.

                  檢索每個模型并單獨運行刪除查詢絕對不是優(yōu)化此操作的好方法,因為您將執(zhí)行數(shù)百萬個查詢.如果您希望嘗試限制應用程序中的每秒負載而不是優(yōu)化數(shù)據(jù)庫服務器來處理此查詢,則可以使用帶有刪除限制的 while 循環(huán):

                  Retrieving each model and running a delete query individually definitely isn't a good way to optimize this as you'd be executing millions of queries. You could use a while loop with a delete limit if you wish to try to limit the load per second in your application instead of optimizing your database server to handle this query:

                  do {
                      $deleted = Post::where('arch_id', $posts_archive->id)->limit(1000)->delete();
                      sleep(2);
                  } while ($deleted > 0);
                  

                  這篇關于Laravel 塊和刪除的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)

                    <tbody id='VUDrn'></tbody>
                    <legend id='VUDrn'><style id='VUDrn'><dir id='VUDrn'><q id='VUDrn'></q></dir></style></legend>
                  • <tfoot id='VUDrn'></tfoot>

                  • <i id='VUDrn'><tr id='VUDrn'><dt id='VUDrn'><q id='VUDrn'><span id='VUDrn'><b id='VUDrn'><form id='VUDrn'><ins id='VUDrn'></ins><ul id='VUDrn'></ul><sub id='VUDrn'></sub></form><legend id='VUDrn'></legend><bdo id='VUDrn'><pre id='VUDrn'><center id='VUDrn'></center></pre></bdo></b><th id='VUDrn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VUDrn'><tfoot id='VUDrn'></tfoot><dl id='VUDrn'><fieldset id='VUDrn'></fieldset></dl></div>
                      • <bdo id='VUDrn'></bdo><ul id='VUDrn'></ul>

                        <small id='VUDrn'></small><noframes id='VUDrn'>

                            主站蜘蛛池模板: 欧美一级在线观看 | 9久9久| 第一av| 亚洲精品国产电影 | 亚洲一区二区久久久 | 99热最新| 久久久久免费观看 | 亚洲在线一区 | 国产精品日产欧美久久久久 | 国产精品a久久久久 | 久久成人18免费网站 | 在线色网| 一级特黄色毛片 | 一区免费观看 | 亚洲视频在线观看 | 欧美一区二区三区久久精品 | 国产一区二区在线播放 | 国产小网站 | 久久久久国产一区二区三区四区 | 国产成人影院 | 欧美视频免费在线 | 久久久久中文字幕 | 成人精品一区 | 91网站在线播放 | 国产精品99久久久久久动医院 | 美女一级a毛片免费观看97 | www.日本在线播放 | 91影院在线观看 | 天堂在线一区 | 人人爽人人爽 | 草久久久 | 免费一二区 | 黑色丝袜三级在线播放 | www.亚洲.com| 日韩另类 | 香蕉视频久久久 | 天天爽网站 | 三级特黄特色视频 | 极情综合网 | 日韩区| 午夜精品久久久久久久星辰影院 |