[o2on-svn] [126] 管理画面、DBからのデータ取得を一度に行うように変更

Back to archive index

o2on svn commit o2on-****@lists*****
2008年 11月 2日 (日) 02:05:52 JST


Revision: 126
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=o2on&view=rev&rev=126
Author:   laxmi
Date:     2008-11-02 02:05:52 +0900 (Sun, 02 Nov 2008)

Log Message:
-----------
管理画面、DBからのデータ取得を一度に行うように変更
http://pc11.2ch.net/test/read.cgi/tech/1212302014/520

Modified Paths:
--------------
    trunk/o2on/src.o2on/O2DatDB.cpp
    trunk/o2on/src.o2on/O2DatDB.h
    trunk/o2on/src.o2on/O2ReportMaker.cpp

Modified: trunk/o2on/src.o2on/O2DatDB.cpp
===================================================================
--- trunk/o2on/src.o2on/O2DatDB.cpp	2008-10-14 12:51:27 UTC (rev 125)
+++ trunk/o2on/src.o2on/O2DatDB.cpp	2008-11-01 17:05:52 UTC (rev 126)
@@ -799,54 +799,6 @@
 
 uint64
 O2DatDB::
-select_datcount(void)
-{
-#if TRACE_SQL_EXEC_TIME
-	stopwatch sw("select datcount");
-#endif
-
-	sqlite3 *db = NULL;
-	sqlite3_stmt *stmt = NULL;
-
-	int err = sqlite3_open16(dbfilename.c_str(), &db);
-	if (err != SQLITE_OK)
-		goto error;
-
-	sqlite3_busy_timeout(db, 5000);
-
-	wchar_t *sql = L"select count(*) from dat;";
-
-	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
-	if (err != SQLITE_OK)
-		goto error;
-
-	err = sqlite3_step(stmt);
-	if (err != SQLITE_ROW && err != SQLITE_DONE)
-		goto error;
-
-	uint64 count = sqlite3_column_int64(stmt,0);
-
-	sqlite3_finalize(stmt);
-	stmt = NULL;
-
-	err = sqlite3_close(db);
-	if (err != SQLITE_OK)
-		goto error;
-
-	return (count);
-
-error:
-	log(db);
-	if (stmt) sqlite3_finalize(stmt);
-	if (db) sqlite3_close(db);
-	return (0);
-}
-
-
-
-
-uint64
-O2DatDB::
 select_datcount(wstrnummap &out)
 {
 #if TRACE_SQL_EXEC_TIME
@@ -904,7 +856,7 @@
 select_totaldisksize(void)
 {
 #if TRACE_SQL_EXEC_TIME
-	stopwatch sw("select totakdisksize");
+	stopwatch sw("select totaldisksize");
 #endif
 
 	sqlite3 *db = NULL;
@@ -946,12 +898,12 @@
 
 
 
-uint64
+void
 O2DatDB::
-select_publishcount(time_t publish_tt)
+select_report(time_t publish_tt, uint64 &count, uint64 &disksize, uint64 &publish)
 {
 #if TRACE_SQL_EXEC_TIME
-	stopwatch sw("select datcount by lastpublish");
+	stopwatch sw("select report");
 #endif
 
 	sqlite3 *db = NULL;
@@ -960,9 +912,13 @@
 	int err = sqlite3_open16(dbfilename.c_str(), &db);
 	if (err != SQLITE_OK)
 		goto error;
+
 	sqlite3_busy_timeout(db, 5000);
 
-	wchar_t *sql = L"select count(*) from dat where lastpublish > ?;";
+	wchar_t *sql = L"select count(*),"
+			L"sum(disksize),"
+			L"sum(case when lastpublish > ? then 1 else 0 end)"
+			L"from dat;";
 
 	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
 	if (err != SQLITE_OK)
@@ -970,12 +926,14 @@
 
 	if (!bind(db, stmt, 1, time(NULL)-publish_tt))
 		goto error;
-
+	
 	err = sqlite3_step(stmt);
 	if (err != SQLITE_ROW && err != SQLITE_DONE)
 		goto error;
 
-	uint64 count = sqlite3_column_int64(stmt,0);
+	count = sqlite3_column_int64(stmt,0);
+	disksize = sqlite3_column_int64(stmt,1);
+	publish = sqlite3_column_int64(stmt,2);
 
 	sqlite3_finalize(stmt);
 	stmt = NULL;
@@ -984,13 +942,13 @@
 	if (err != SQLITE_OK)
 		goto error;
 
-	return (count);
+	return;
 
 error:
 	log(db);
 	if (stmt) sqlite3_finalize(stmt);
 	if (db) sqlite3_close(db);
-	return (0);
+	return;
 }
 
 

Modified: trunk/o2on/src.o2on/O2DatDB.h
===================================================================
--- trunk/o2on/src.o2on/O2DatDB.h	2008-10-14 12:51:27 UTC (rev 125)
+++ trunk/o2on/src.o2on/O2DatDB.h	2008-11-01 17:05:52 UTC (rev 126)
@@ -95,10 +95,9 @@
 	bool select(O2DatRecList &out, const wchar_t *domain, const wchar_t *bbsname);
 	bool select(O2DatRec &out, const wchar_t *domain, const wchar_t *bbsname, const wchar_t *datname);
 	bool select(O2DatRecList &out, time_t publish_tt, size_t limit);
-	uint64 select_datcount(void);
 	uint64 select_datcount(wstrnummap &out);
 	uint64 select_totaldisksize(void);
-	uint64 select_publishcount(time_t publish_tt);
+	void select_report(time_t publish_tt, uint64 &count, uint64 &disksize, uint64 &publish);
 
 	void insert(O2DatRecList &in, bool to_rebuild);
 

Modified: trunk/o2on/src.o2on/O2ReportMaker.cpp
===================================================================
--- trunk/o2on/src.o2on/O2ReportMaker.cpp	2008-10-14 12:51:27 UTC (rev 125)
+++ trunk/o2on/src.o2on/O2ReportMaker.cpp	2008-11-01 17:05:52 UTC (rev 126)
@@ -176,10 +176,11 @@
 		(total_uptime == 0 ? 0 : (double)(accum_total_u+accum_total_d)/total_uptime*8));
 
 	//dat”AƒTƒCƒY
-	uint64 datnum = DatDB->select_datcount();
-	uint64 datsize = DatDB->select_totaldisksize();
-	uint64 pubnum = DatDB->select_publishcount(PUBLISH_ORIGINAL_TT);
-
+	uint64 datnum = 0;
+	uint64 datsize = 0;
+	uint64 pubnum = 0;
+	DatDB->select_report(PUBLISH_ORIGINAL_TT, datnum, datsize, pubnum);
+	
 	//publish—¦
 	wchar_t publishper[32];
 	if (datnum == 0)




o2on-svn メーリングリストの案内
Back to archive index