Explorar el Código

Update StatusTagsPipeline, deduplicate hashtags on postgres

Daniel Supernault hace 2 años
padre
commit
867cbc757c
Se han modificado 1 ficheros con 18 adiciones y 5 borrados
  1. 18 5
      app/Jobs/StatusPipeline/StatusTagsPipeline.php

+ 18 - 5
app/Jobs/StatusPipeline/StatusTagsPipeline.php

@@ -71,11 +71,24 @@ class StatusTagsPipeline implements ShouldQueue
                 }
                 }
             }
             }
 
 
-			$hashtag = Hashtag::firstOrCreate([
-				'slug' => str_slug($name)
-			], [
-				'name' => $name
-			]);
+            if(config('database.default') === 'pgsql') {
+            	$hashtag = Hashtag::where('name', 'ilike', $name)
+            		->orWhere('slug', 'ilike', str_slug($name))
+            		->first();
+
+            	if(!$hashtag) {
+            		$hashtag = new Hashtag;
+            		$hashtag->name = $name;
+            		$hashtag->slug = str_slug($name);
+            		$hashtag->save();
+            	}
+            } else {
+				$hashtag = Hashtag::firstOrCreate([
+					'slug' => str_slug($name)
+				], [
+					'name' => $name
+				]);
+            }
 
 
 			StatusHashtag::firstOrCreate([
 			StatusHashtag::firstOrCreate([
 				'status_id' => $status->id,
 				'status_id' => $status->id,