]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-sql: Don't try to optimize finding a matching map by using the previous match.
authorTimo Sirainen <tss@iki.fi>
Tue, 9 Jun 2015 16:32:09 +0000 (19:32 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 9 Jun 2015 16:32:09 +0000 (19:32 +0300)
In some setups multiple maps can match and it's important that the matching
is done in the same order always, otherwise the results could become
somewhat random.

src/lib-dict/dict-sql.c

index b130c6d759af9351aab22632d23d57bd54cd17a3..e8ee408204f7b94a7a5e0765aef8dd526c11163e 100644 (file)
@@ -28,7 +28,6 @@ struct sql_dict {
        struct sql_db *db;
        const char *username;
        const struct dict_sql_settings *set;
-       unsigned int prev_map_match_idx;
 
        unsigned int has_on_duplicate_key:1;
 };
@@ -190,18 +189,14 @@ sql_dict_find_map(struct sql_dict *dict, const char *path,
                  ARRAY_TYPE(const_string) *values)
 {
        const struct dict_sql_map *maps;
-       unsigned int i, idx, count, len;
+       unsigned int i, count, len;
 
        t_array_init(values, dict->set->max_field_count);
        maps = array_get(&dict->set->maps, &count);
        for (i = 0; i < count; i++) {
-               /* start matching from the previously successful match */
-               idx = (dict->prev_map_match_idx + i) % count;
-               if (dict_sql_map_match(&maps[idx], path, values,
-                                      &len, &len, FALSE, FALSE)) {
-                       dict->prev_map_match_idx = idx;
-                       return &maps[idx];
-               }
+               if (dict_sql_map_match(&maps[i], path, values,
+                                      &len, &len, FALSE, FALSE))
+                       return &maps[i];
        }
        return NULL;
 }