Commit 732b4d9d authored by mouadh's avatar mouadh

optimization 1 (free ram space after loading page)

parent 0f8cb74f
from __future__ import absolute_import, division, print_function
from sqlalchemy import inspect
import pandas as pd
from ..tools.mem_bench import memory_usage
from ..tools.connection import MyDB
import pandas.io.sql as psql
......@@ -19,12 +19,37 @@ def _load_tables_db(executer_instance):
memory_usage("1 - before executing query //// _load_tables_db")
for table_name in inspector.get_table_names():
value = psql.read_sql_query(
'SELECT * FROM "{0}"'.format(table_name), db.engine)
# value = psql.read_sql_query(
# 'SELECT * FROM "{0}"'.format(table_name), db.engine)
# results = db.engine.execute('SELECT * FROM "{0}"'.format(table_name))
results = (db.engine
.execution_options(stream_results=True)
.execute('SELECT * FROM "{0}"'.format(table_name)))
# Fetch all the results of the query
fetchall = results.fetchall()
# fetchall = results.fetchone()
value = pd.DataFrame(fetchall,columns=results.keys())
tables[table_name] = value[[
col for col in value.columns if col.lower()[-3:] != '_id'
]]
# tables = {}
# db = MyDB(db_config_file_path=executer_instance.DATA_FOLDER, db=executer_instance.cube)
# # inspector = inspect(db.engine)
# cursor = db.engine.cursor()
# cursor.execute("""SELECT table_name FROM information_schema.tables
# WHERE table_schema = 'public'""")
#
# for table_name in cursor.fetchall():
# value = psql.read_sql_query(
# 'SELECT * FROM "{0}" '.format(table_name[0]), db.engine)
#
# tables[table_name[0]] = value[[
# col for col in value.columns if col.lower()[-3:] != '_id'
# ]]
memory_usage("2 - after query, before fetchall /////// _load_tables_db")
return tables
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment