Commit ddf478b 1 parent 162fcb7 commit ddf478b Copy full SHA for ddf478b
File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -162,3 +162,22 @@ def compliance_checks(article_id):
162
162
report .save ()
163
163
logger .info ("Compliance checks completed for article %s" , article_id )
164
164
return f"Compliance checks completed for article { article_id } "
165
+
166
+
167
+ from django .core .paginator import Paginator
168
+ from scoap3 .articles .models import Article
169
+ from django_opensearch_dsl .registries import registry
170
+
171
+ @shared_task
172
+ def index_article_batch (article_ids ):
173
+ articles = Article .objects .filter (id__in = article_ids )
174
+ for article in articles :
175
+ registry .update (article )
176
+
177
+ def index_all_articles (batch_size = 100 ):
178
+ all_articles = Article .objects .all ().values_list ('id' , flat = True )
179
+ paginator = Paginator (all_articles , batch_size )
180
+
181
+ for page_number in paginator .page_range :
182
+ page = paginator .page (page_number )
183
+ index_article_batch .delay (list (page .object_list ))
Original file line number Diff line number Diff line change
1
+ import math
2
+
3
+ from django .core .files .storage import storages
4
+ from django .core .management .base import BaseCommand , CommandParser
5
+
6
+ from scoap3 .articles .tasks import index_all_articles
7
+
8
+
9
+ class Command (BaseCommand ):
10
+ help = "Article indexing commands"
11
+
12
+ def add_arguments (self , parser : CommandParser ) -> None :
13
+ parser .add_argument (
14
+ "--from-id" ,
15
+ type = int ,
16
+ default = None ,
17
+ required = False ,
18
+ help = "Article id to start the indexing FROM." ,
19
+ )
20
+
21
+ parser .add_argument (
22
+ "--batch-size" ,
23
+ type = int ,
24
+ default = 1000 ,
25
+ required = False ,
26
+ help = "Batchsize to migrate per task." ,
27
+ )
28
+
29
+ def handle (self , * args , ** options ):
30
+ index_all_articles (options ['batch_size' ])
You can’t perform that action at this time.
0 commit comments