add timed decorator for perf tracking
This commit is contained in:
parent
996ac3c337
commit
f367b0ab2a
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import time
|
||||
from collections import defaultdict
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from collections import defaultdict
|
||||
|
@ -10,6 +12,20 @@ from django.db import transaction
|
|||
from polymorphic.models import PolymorphicModel
|
||||
|
||||
|
||||
def timed(method):
|
||||
""""
|
||||
A simple decorator to measure time elapsed in class function (hence the args[0])
|
||||
"""
|
||||
def _timed(*args, **kw):
|
||||
ts = time.time()
|
||||
result = method(*args, **kw)
|
||||
te = time.time()
|
||||
args[0].print_success(f"{method.__name__} executed ({te-ts:.2f}s)")
|
||||
return result
|
||||
|
||||
return _timed
|
||||
|
||||
|
||||
class ImportCommand(BaseCommand):
|
||||
"""
|
||||
Generic command for import of NK15 database
|
||||
|
|
|
@ -15,7 +15,7 @@ from note.models import Note, NoteUser, NoteClub
|
|||
from note.models import Alias
|
||||
from member.models import Club, Profile
|
||||
|
||||
from ._import_utils import ImportCommand, BulkCreateManager
|
||||
from ._import_utils import ImportCommand, BulkCreateManager, timed
|
||||
|
||||
M_DURATION = 396
|
||||
M_START = datetime.date(2019, 8, 31)
|
||||
|
@ -44,6 +44,8 @@ class Command(ImportCommand):
|
|||
def add_arguments(self, parser):
|
||||
parser.add_argument('-a', '--alias', action='store_true', help="import alias")
|
||||
|
||||
|
||||
@timed
|
||||
@transaction.atomic
|
||||
def import_account(self, cur, chunk_size):
|
||||
"""
|
||||
|
@ -157,6 +159,7 @@ class Command(ImportCommand):
|
|||
bulk_mgr.done()
|
||||
self.print_success("comptes table imported")
|
||||
|
||||
@timed
|
||||
def import_alias(self, cur, chunk_size):
|
||||
"""
|
||||
Import Alias from nk15
|
||||
|
|
|
@ -22,7 +22,7 @@ class Command(ImportCommand):
|
|||
|
||||
def add_arguments(self, parser):
|
||||
pass
|
||||
|
||||
@timed
|
||||
@transaction.atomic
|
||||
def import_activities(self, cur, chunk_size):
|
||||
cur.execute("SELECT * FROM activites ORDER by id")
|
||||
|
@ -58,6 +58,7 @@ class Command(ImportCommand):
|
|||
bulk_mgr.done()
|
||||
return MAP_IDACTIVITY, MAP_NAMEACTIVITY
|
||||
|
||||
@timed
|
||||
@transaction.atomic
|
||||
def import_activity_entries(cur):
|
||||
bulk_mgr = BulkCreateManager()
|
||||
|
|
Loading…
Reference in New Issue