File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change
1
+ import time
2
+
1
3
from django .core .management .base import BaseCommand
2
4
from django .db import transaction
3
5
4
6
from ...models import Document
5
7
6
8
7
9
class Command (BaseCommand ):
8
- @ transaction . atomic
10
+
9
11
def handle (self , * args , ** options ):
10
12
"""
11
13
Update Document's search vector field in an atomic transaction.
12
14
13
15
Inside an atomic transaction all not null search vector values are set
14
16
to null and than the field are updated using the document definition.
15
17
"""
16
- Document .objects .search_reset ()
17
- updated_documents = Document .objects .search_update ()
18
+ _started_at = time .time ()
19
+ with transaction .atomic ():
20
+ Document .objects .search_reset ()
21
+ updated_documents = Document .objects .search_update ()
22
+ elapsed = time .time () - _started_at
18
23
if options ["verbosity" ] >= 2 :
19
24
self .stdout .write (
20
25
self .style .SUCCESS (
21
- f"Successfully indexed { updated_documents } documents."
26
+ f"Indexed { updated_documents } documents in { elapsed :.03 } s ."
22
27
)
23
28
)
You can’t perform that action at this time.
0 commit comments