모델의 쿼리 세트를 반복하고 일치하는 모든 것들을 삭제하기위한 django 코드의 스 니펫이 있습니다. queryset이 커졌으며 이러한 작업은 실제로 주기적 작업으로 설정되므로 속도가 문제가되고 있습니다.큰 쿼리 세트에서 일치하는 모델을 삭제하는 코드를 최적화하는 데 도움이 필요합니다.
누구나 코드를 최적화하려고합니다.
# For the below code, "articles" are just django models
all_articles = [a reallly large list of articles]
newest_articles = [some large list of new articles]
unique_articles = []
for new_article in newest_articles:
failed = False
for old_article in all_articles:
# is_similar is just a method which checks if two strings are
# identical to a certain degree
if is_similar(new_article.blurb, old_article.blurb, 0.9)
and is_similar(new_article.title, old_article.title, 0.92):
failed = True
break
if not failed:
unique_articles.append(new_article)
return unique_articles
감사합니다.
데이터베이스 연산에서'is_similar()'를 정의 할 수 있습니까? –
아무 것도 알지 못한다면 두 입력 문자열이 동일한 지 비교합니다. –
어떤 데이터베이스를 사용하고 있습니까? – atereshkin