Skip to content

Commit

Permalink
Remove unnecessary code parts
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanakg committed Feb 13, 2024
1 parent bb01bbd commit aa61528
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions app/Jobs/ImportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ private function handleNew(CSVImportReader $reader)
$filepath = Storage::disk('local')
->path('mismatch-files/' . $this->meta->filename);



DB::transaction(function () use ($filepath, $reader) {
$mismatch_attrs = (new Mismatch())->getFillable();

$fileLines = [];
$whereClause = [];
$whereClauses = [];

$mismatches_per_upload_user = DB::table('mismatches')
->select($mismatch_attrs)
Expand All @@ -110,42 +108,26 @@ private function handleNew(CSVImportReader $reader)
$mismatch_attrs,
&$fileLines,
$mismatches_per_upload_user,
&$whereClause
&$whereClauses
) {

$new_mismatch = Mismatch::make($mismatchLine);
$fileLines[] = $new_mismatch;
$collection = collect($new_mismatch->getAttributes());
$collection->forget('review_status');
$newArray = [['review_status', '!=', 'pending']];
// dd($mismatch_attrs, $collection, $new_mismatch->getAttributes());
$collection->map(function ($item, $key) use (&$newArray) {
if ($key != 'type') { // key can be empty in the file but in the db always has statement by default
$newArray[] = [$key, $item];
}
});


$whereClause[] = $newArray;

// $count = $mismatches_per_upload_user->count();
// $row_in_db = $mismatches_per_upload_user->orWhere(function ($query) use ($newArray) {
// $query->orWhere($newArray);
// });
//
// $start = hrtime(true);
// if ($row_in_db->doesntExist()) {
// $timespan = (hrtime(true) - $start) / 1000000;
// Log::info("DB check timespan:\t {$timespan}ms");
// $start = hrtime(true);
//// $this->saveMismatch($new_mismatch);
// $timespan = (hrtime(true) - $start) / 1000000;
// Log::info("DB save timespan:\t {$timespan}ms");
// }
$whereClauses[] = $newArray;
});

$mismatches_per_upload_user->where(function ($query) use ($whereClause) {
foreach ($whereClause as $where) {
$mismatches_per_upload_user->where(function ($query) use ($whereClauses) {
foreach ($whereClauses as $where) {
$query->orWhere(function ($query) use ($where) {
$query->where($where);
});
Expand All @@ -154,7 +136,7 @@ private function handleNew(CSVImportReader $reader)
$result = $mismatches_per_upload_user->get();

foreach ($fileLines as $fileLine) {
if ($result->contains(function ($value, $key) use ($fileLine) {
if ($result->contains(function ($value) use ($fileLine) {
$metaAttrs = $fileLine->getAttributes();
foreach ($metaAttrs as $attrKey => $attr) {
$value = (array)$value;
Expand Down

0 comments on commit aa61528

Please sign in to comment.