mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-22 14:57:02 +01:00
g10: Don't cache search results if the search didn't scan the whole DB.
* g10/keydb.c (struct keydb_handle): Add new field is_reset. (keydb_new): Initialize hd->is_reset to 1. (keydb_locate_writable): Set hd->is_reset to 1. (keydb_search): Set hd->is_reset to 0. Don't cache a key not found if the search started from the beginning of the database. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>.
This commit is contained in:
parent
11d8ffc939
commit
efd1ead9e7
11
g10/keydb.c
11
g10/keydb.c
@ -69,6 +69,11 @@ struct keydb_handle
|
|||||||
int saved_found;
|
int saved_found;
|
||||||
unsigned long skipped_long_blobs;
|
unsigned long skipped_long_blobs;
|
||||||
int no_caching;
|
int no_caching;
|
||||||
|
|
||||||
|
/* Whether the next search will be from the beginning of the
|
||||||
|
database (and thus consider all records). */
|
||||||
|
int is_reset;
|
||||||
|
|
||||||
int current;
|
int current;
|
||||||
int used; /* Number of items in ACTIVE. */
|
int used; /* Number of items in ACTIVE. */
|
||||||
struct resource_item active[MAX_KEYDB_RESOURCES];
|
struct resource_item active[MAX_KEYDB_RESOURCES];
|
||||||
@ -676,6 +681,7 @@ keydb_new (void)
|
|||||||
hd = xmalloc_clear (sizeof *hd);
|
hd = xmalloc_clear (sizeof *hd);
|
||||||
hd->found = -1;
|
hd->found = -1;
|
||||||
hd->saved_found = -1;
|
hd->saved_found = -1;
|
||||||
|
hd->is_reset = 1;
|
||||||
|
|
||||||
assert (used_resources <= MAX_KEYDB_RESOURCES);
|
assert (used_resources <= MAX_KEYDB_RESOURCES);
|
||||||
for (i=j=0; i < used_resources; i++)
|
for (i=j=0; i < used_resources; i++)
|
||||||
@ -1568,6 +1574,7 @@ keydb_search_reset (KEYDB_HANDLE hd)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hd->is_reset = 1;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1630,6 +1637,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
|
|||||||
size_t ndesc, size_t *descindex)
|
size_t ndesc, size_t *descindex)
|
||||||
{
|
{
|
||||||
gpg_error_t rc;
|
gpg_error_t rc;
|
||||||
|
int was_reset = hd->is_reset;
|
||||||
int already_in_cache = 0;
|
int already_in_cache = 0;
|
||||||
|
|
||||||
if (descindex)
|
if (descindex)
|
||||||
@ -1696,6 +1704,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
|
|||||||
else if (!rc)
|
else if (!rc)
|
||||||
hd->found = hd->current;
|
hd->found = hd->current;
|
||||||
}
|
}
|
||||||
|
hd->is_reset = 0;
|
||||||
|
|
||||||
rc = ((rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF)
|
rc = ((rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF)
|
||||||
? gpg_error (GPG_ERR_NOT_FOUND)
|
? gpg_error (GPG_ERR_NOT_FOUND)
|
||||||
@ -1712,7 +1721,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND
|
if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND
|
||||||
&& ndesc == 1 && desc[0].mode == KEYDB_SEARCH_MODE_LONG_KID
|
&& ndesc == 1 && desc[0].mode == KEYDB_SEARCH_MODE_LONG_KID && was_reset
|
||||||
&& !already_in_cache)
|
&& !already_in_cache)
|
||||||
kid_not_found_insert (desc[0].u.kid);
|
kid_not_found_insert (desc[0].u.kid);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user