Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Commit

Permalink
check if we have a dupe during celery task
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmithgall committed Feb 21, 2015
1 parent d0b53a6 commit a927bee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lmgtfy/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from celery import shared_task
from django.conf import settings
from django.core.exceptions import DoesNotExist

from bingpy import WebSearch

Expand Down Expand Up @@ -46,14 +47,21 @@ def search_bing_task(domain_search_record):
file_size = 0
file_type = 'unknown'

result_model_objects.append(DomainSearchResult(
new_result = DomainSearchResult(
search_instance=domain_search_record,
result=result_url,
fmt=file_format,
title=result.title,
size=int(file_size) / 1024,
content_type=file_type
))
)

try:
DomainSearchResult.objects.get(new_result)
continue
except DoesNotExist:
result_model_objects.append(new_result)

# if there are results, batch them up and save them as we iterate.
if len(result_model_objects) >= 20:
DomainSearchResult.objects.bulk_create( result_model_objects )
Expand Down

0 comments on commit a927bee

Please sign in to comment.