在Google云端硬盘文件中搜索文字需要时间

时间:2016-02-23 14:23:41

标签: google-drive-api drive

我有此功能可以搜索Google云端硬盘文件中的文字,并且需要超过4分钟才能搜索600个Google云端硬盘文件中的文字。有没有办法优化代码?

System.out.println(“printFilesInFolder:”);

     Files.List req = null;
     List<File> result = new ArrayList<File>();
        Children.List request = service.children().list(folderId).setQ("trashed=false");

        do {
          try {
            ChildList children = request.execute();
           System.out.println("children size  >>>>>>>>>>>  : "+ children.size());


            for (ChildReference child : children.getItems()) {

              System.out.println("File Id: " + child.getId());

              if( !(children.getItems().isEmpty())){
                   System.out.println("not empty >>>>>>>>>");

                   String subFolderId = child.getId();

                   req = service.files().list().setQ("'"+subFolderId+"' in parents and trashed=false and fullText contains '"+keyword+"'");


                     do{
                         System.out.println("inside do  " + req.size());
                            try
                            {
                                 try {
                                     FileList children1 = req.execute();
                                     result.addAll(children1.getItems());
                                     req.setPageToken(children1.getNextPageToken());


                                 } catch (IOException e) {
                                     req.setPageToken(null);
                                 }


                            }
                            catch(Exception e)
                            {
                            }

                     }
                     while(req.getPageToken() != null && req.getPageToken().length() > 0);
            }

           }
            request.setPageToken(children.getNextPageToken());
          } catch (IOException e) {
            System.out.println("An error occurred: " + e);
            request.setPageToken(null);
          }
        } while (request.getPageToken() != null &&
                 request.getPageToken().length() > 0);

0 个答案:

没有答案