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

check if we have a dupe during celery task #34

Merged
merged 1 commit into from
Feb 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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