Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6481:e81e56e67ba1 HEAD
Use dicts directly instead of caching them. Caching doesn't help much here.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 22 Sep 2007 19:40:43 +0300 |
parents | 7596339a9452 |
children | c02c7912fb15 |
files | src/dict/Makefile.am src/dict/dict-cache.c src/dict/dict-cache.h src/dict/dict-server.c |
diffstat | 4 files changed, 4 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dict/Makefile.am Sat Sep 22 19:40:06 2007 +0300 +++ b/src/dict/Makefile.am Sat Sep 22 19:40:43 2007 +0300 @@ -26,10 +26,8 @@ dict_DEPENDENCIES = $(libs) dict_SOURCES = \ - dict-cache.c \ dict-server.c \ main.c noinst_HEADERS = \ - dict-cache.h \ dict-server.h
--- a/src/dict/dict-cache.c Sat Sep 22 19:40:06 2007 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */ - -#include "lib.h" -#include "hash.h" -#include "dict.h" -#include "dict-cache.h" - -struct dict_entry { - int refcount; - char *user_uri; - struct dict *dict; -}; - -struct dict_cache { - struct hash_table *dicts; /* uri -> struct dict_entry */ -}; - -struct dict_cache *dict_cache_init(void) -{ - struct dict_cache *cache; - - cache = i_new(struct dict_cache, 1); - cache->dicts = hash_create(default_pool, default_pool, 0, str_hash, - (hash_cmp_callback_t *)strcmp); - return cache; -} - -void dict_cache_deinit(struct dict_cache *cache) -{ - hash_destroy(&cache->dicts); - i_free(cache); -} - -struct dict *dict_cache_get(struct dict_cache *cache, const char *uri, - enum dict_data_type value_type, - const char *username) -{ - struct dict_entry *entry; - char *user_uri; - - user_uri = i_strdup_printf("%s\t%s", username, uri); - entry = hash_lookup(cache->dicts, user_uri); - if (entry == NULL) { - entry = i_new(struct dict_entry, 1); - entry->dict = dict_init(uri, value_type, username); - entry->user_uri = user_uri; - hash_insert(cache->dicts, entry->user_uri, entry); - } else { - i_free(user_uri); - } - entry->refcount++; - return entry->dict; -} - -void dict_cache_unref(struct dict_cache *cache, const char *uri, - const char *username) -{ - struct dict_entry *entry; - - t_push(); - entry = hash_lookup(cache->dicts, - t_strdup_printf("%s\t%s", username, uri)); - i_assert(entry != NULL && entry->refcount > 0); - - if (--entry->refcount == 0) { - hash_remove(cache->dicts, entry->user_uri); - dict_deinit(&entry->dict); - i_free(entry->user_uri); - i_free(entry); - } - t_pop(); -}
--- a/src/dict/dict-cache.h Sat Sep 22 19:40:06 2007 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -#ifndef DICT_CACHE_H -#define DICT_CACHE_H - -struct dict_cache *dict_cache_init(void); -void dict_cache_deinit(struct dict_cache *cache); - -struct dict *dict_cache_get(struct dict_cache *cache, const char *uri, - enum dict_data_type value_type, - const char *username); -void dict_cache_unref(struct dict_cache *cache, const char *uri, - const char *username); - -#endif
--- a/src/dict/dict-server.c Sat Sep 22 19:40:06 2007 +0300 +++ b/src/dict/dict-server.c Sat Sep 22 19:40:43 2007 +0300 @@ -7,7 +7,6 @@ #include "istream.h" #include "ostream.h" #include "dict.h" -#include "dict-cache.h" #include "dict-client.h" #include "dict-server.h" @@ -23,7 +22,7 @@ struct dict_server *server; char *username; - char *name, *uri; + char *name; struct dict *dict; enum dict_data_type value_type; @@ -41,8 +40,6 @@ char *path; int fd; struct io *io; - - struct dict_cache *cache; }; struct dict_client_cmd { @@ -347,9 +344,7 @@ return -1; } - conn->uri = i_strdup(uri); - conn->dict = dict_cache_get(conn->server->cache, conn->uri, - conn->value_type, conn->username); + conn->dict = dict_init(uri, conn->value_type, conn->username); if (conn->dict == NULL) { /* dictionary initialization failed */ i_error("Failed to initialize dictionary '%s'", conn->name); @@ -430,12 +425,9 @@ if (close(conn->fd) < 0) i_error("close(dict client) failed: %m"); - if (conn->dict != NULL) { - dict_cache_unref(conn->server->cache, conn->uri, - conn->username); - } + if (conn->dict != NULL) + dict_deinit(&conn->dict); i_free(conn->name); - i_free(conn->uri); i_free(conn->username); i_free(conn); } @@ -497,13 +489,11 @@ server->io = io_add(server->fd, IO_READ, dict_server_listener_accept, server); - server->cache = dict_cache_init(); return server; } void dict_server_deinit(struct dict_server *server) { - dict_cache_deinit(server->cache); io_remove(&server->io); if (close(server->fd) < 0) i_error("close(%s) failed: %m", server->path);