Skip to content

Commit

Permalink
Merge pull request #1567 from jhelmold/after_scanner_task_stuck
Browse files Browse the repository at this point in the history
Solved a peformance problem for tasks after scanning lots of hosts.
  • Loading branch information
timopollmeier authored Jun 23, 2021
2 parents ab8f971 + 3498c4c commit 1eff5b9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Update subject alternative name in certificate generation [#1503](https://github.com/greenbone/gvmd/pull/1503)
- Fix whole-only config family selection [#1517](https://github.com/greenbone/gvmd/pull/1517)
- Migrate GMP Scanners to OSP Sensors [#1533](https://github.com/greenbone/gvmd/pull/1533)
- Solved a peformance problem for tasks after scanning lots of hosts [#1567](https://github.com/greenbone/gvmd/pull/1567)

[21.4.0]: https://github.com/greenbone/gvmd/compare/v21.4.0...gvmd-21.04

Expand Down
57 changes: 38 additions & 19 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -19108,36 +19108,28 @@ host_identify (const char *host_name, const char *identifier_name,
const char *identifier_value, const char *source_type,
const char *source)
{
host_t host;
host_t host = 0;
gchar *quoted_host_name, *quoted_identifier_name, *quoted_identifier_value;

quoted_host_name = sql_quote (host_name);
quoted_identifier_name = sql_quote (identifier_name);
quoted_identifier_value = sql_quote (identifier_value);

switch (sql_int64 (&host,
"SELECT id FROM hosts"
" WHERE name = '%s'"
" AND owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND (EXISTS (SELECT * FROM host_identifiers"
" WHERE host = hosts.id"
" AND owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND name = '%s'"
" AND value = '%s')"
" OR NOT EXISTS (SELECT * FROM host_identifiers"
" WHERE host = hosts.id"
" AND owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND name = '%s'));",
"SELECT hosts.id FROM hosts, host_identifiers"
" WHERE hosts.name = '%s'"
" AND hosts.owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND host = hosts.id"
" AND host_identifiers.owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND host_identifiers.name = '%s'"
" AND value = '%s';",
quoted_host_name,
current_credentials.uuid,
current_credentials.uuid,
quoted_identifier_name,
quoted_identifier_value,
current_credentials.uuid,
quoted_identifier_name))
quoted_identifier_value))
{
case 0:
break;
Expand All @@ -19151,6 +19143,33 @@ host_identify (const char *host_name, const char *identifier_name,
break;
}

if (host == 0)
switch (sql_int64 (&host,
"SELECT id FROM hosts"
" WHERE name = '%s'"
" AND owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND NOT EXISTS (SELECT * FROM host_identifiers"
" WHERE host = hosts.id"
" AND owner = (SELECT id FROM users"
" WHERE uuid = '%s')"
" AND name = '%s');",
quoted_host_name,
current_credentials.uuid,
current_credentials.uuid,
quoted_identifier_name))
{
case 0:
break;
case 1: /* Too few rows in result of query. */
host = 0;
break;
default: /* Programming error. */
assert (0);
case -1:
host = 0;
break;
}

g_free (quoted_host_name);
g_free (quoted_identifier_name);
Expand Down

0 comments on commit 1eff5b9

Please sign in to comment.