数据库统计查询-优化查询语句
parent
6c63e19dcf
commit
cc66b94530
|
@ -29,6 +29,7 @@ def jx_timestamp():
|
||||||
|
|
||||||
|
|
||||||
class DataVViewSet(GenericViewSet):
|
class DataVViewSet(GenericViewSet):
|
||||||
|
permission_classes = []
|
||||||
queryset = LoginLog.objects.all()
|
queryset = LoginLog.objects.all()
|
||||||
serializer_class = LoginLogSerializer
|
serializer_class = LoginLogSerializer
|
||||||
extra_filter_backends = []
|
extra_filter_backends = []
|
||||||
|
@ -97,14 +98,19 @@ class DataVViewSet(GenericViewSet):
|
||||||
tables_list = []
|
tables_list = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
tables_list.append(row)
|
tables_list.append(row)
|
||||||
|
# cursor.execute(
|
||||||
|
# "select table_schema as db, table_name as tb, table_rows as data_rows, index_length / 1024 as 'storage(KB)' from information_schema.tables where table_schema='{}';".format(
|
||||||
|
# DATABASE_NAME))
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"select table_schema as db, table_name as tb, table_rows as data_rows, index_length / 1024 as 'storage(KB)' from information_schema.tables where table_schema='{}';".format(
|
"select table_schema as table_db, sum(index_length) as storage,count(table_name ) as tables from information_schema.tables group by table_schema having table_db='{}';".format(
|
||||||
DATABASE_NAME))
|
DATABASE_NAME))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
sum_space = 0
|
count = 0
|
||||||
|
space = 0
|
||||||
for row in rows:
|
for row in rows:
|
||||||
sum_space += row[3]
|
count = row[2]
|
||||||
database_info = {"count": len(tables_list), "space": round(sum_space / 1024, 2)}
|
space = round(row[1] / 1024 / 1024, 2)
|
||||||
|
database_info = {"count": count, "space": space}
|
||||||
data = {
|
data = {
|
||||||
"today_register": today_register,
|
"today_register": today_register,
|
||||||
"today_login": today_login,
|
"today_login": today_login,
|
||||||
|
|
Loading…
Reference in New Issue