From 47431e88cb6cb245ae1d977f5eaff61b52f96a43 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 15 Mar 2019 17:56:29 +0400 Subject: pica-client: implement cleaning inactive nodes --- pica-client/nodes.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'pica-client/nodes.cpp') diff --git a/pica-client/nodes.cpp b/pica-client/nodes.cpp index 9ffbd67..983bb56 100644 --- a/pica-client/nodes.cpp +++ b/pica-client/nodes.cpp @@ -68,7 +68,38 @@ QList Nodes::GetNodes() void Nodes::MakeClean() { + QSqlQuery query; + quint32 count = 0; + + query.exec("select count(*) from nodes"); + + if (lasterr.isValid()) + return; + + if (query.next()) + { + count = query.value(0).toUInt(); + } + + if (count > 32) + { + quint32 delcnt; + + query.prepare("select inactive_count from nodes order by inactive_count asc limit 1 offset :halfcount"); + query.bindValue(":halfcount", count / 2); + query.exec(); + if (lasterr.isValid()) + return; + + if (query.next()) + { + delcnt = query.value(0).toUInt(); + query.prepare("delete from nodes where inactive_count >= :delcnt"); + query.bindValue(":delcnt", delcnt); + query.exec(); + } + } } void Nodes::UpdateStatus(NodeRecord &n, bool alive) -- cgit v1.2.1