Skip to content

Commit

Permalink
Merge pull request #539 from SEED-platform/497-export-cache
Browse files Browse the repository at this point in the history
Updating caching for export & caching control via api.
  • Loading branch information
mmclark committed Dec 11, 2015
2 parents 9d54fa9 + f740ef9 commit 545df95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 3 additions & 1 deletion seed/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def export_buildings(export_id, export_name, export_type,
selected_buildings = model.objects.filter(pk__in=building_ids)

def _row_cb(i):
set_cache_raw("export_buildings__%s" % export_id, i)
data = get_cache("export_buildings__%s" % export_id)
data['buildings_processed'] = i
set_cache("export_buildings__%s" % export_id, data['status'], data)

exporter = Exporter(export_id, export_name, export_type)
if not exporter.valid_export_type():
Expand Down
19 changes: 16 additions & 3 deletions seed/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
)
from seed.utils.time import convert_to_js_timestamp
from seed.utils.mapping import get_mappable_types, get_mappable_columns
from seed.utils.cache import get_cache, set_cache
from seed.utils.cache import get_cache, set_cache, get_cache_raw
from .. import search
from seed.lib.exporter import Exporter
from seed.common import mapper as simple_mapper
Expand Down Expand Up @@ -277,15 +277,27 @@ def export_buildings(request):
result = {
'progress_key': progress_key,
'status': 'not-started',
'progress': 0
'progress': 0,
'buildings_processed': 0,
'total_buildings': selected_buildings.count()
}
set_cache(progress_key, result['status'], result)

tasks.export_buildings.delay(export_id, export_name, export_type, building_ids, export_model, selected_fields)

result = {
'progress_key': progress_key,
'status': 'not-started',
'progress': 100,
'buildings_processed': selected_buildings.count(),
'total_buildings': selected_buildings.count()
}
set_cache(progress_key, result['status'], result)
return {
"success": True,
"status": "success",
'progress': 100,
'progress_key': progress_key,
"export_id": export_id,
"total_buildings": selected_buildings.count(),
}
Expand Down Expand Up @@ -316,7 +328,8 @@ def export_buildings_progress(request):
return {
"success": True,
"status": "success",
"buildings_processed": get_cache(progress_key)['progress']
'total_buildings': get_cache(progress_key)['total_buildings'],
"buildings_processed": get_cache(progress_key)['progress'] * get_cache(progress_key)['total_buildings']
}


Expand Down

0 comments on commit 545df95

Please sign in to comment.