diff --git a/CHANGELOG.md b/CHANGELOG.md index fba3cb47..ee02454d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v1.8.6-alpha0 + +* Read `type_count(..)` from cache if available, pr #443. + # v1.8.5 * Added `min()` and `max()` functions, issue #441. diff --git a/inc/ti/fn/fntypecount.h b/inc/ti/fn/fntypecount.h index 48b2fe5c..f9087674 100644 --- a/inc/ti/fn/fntypecount.h +++ b/inc/ti/fn/fntypecount.h @@ -16,7 +16,21 @@ static int do__f_type_count(ti_query_t * query, cleri_node_t * nd, ex_t * e) if (!type) return ti_raw_err_not_found((ti_raw_t *) query->rval, "type", e); - n = ti_query_count_type(query, type); + /* use cache if available */ + if (type->t_cache) + { + n = type->t_cache->n; + } + else + { + ssize_t r = ti_query_count_type(query, type); + if (r < 0) + { + ex_set_mem(e); + return e->nr; + } + n = (size_t) r; + } ti_val_unsafe_drop(query->rval); query->rval = (ti_val_t *) ti_vint_create((int64_t) n); diff --git a/inc/ti/version.h b/inc/ti/version.h index 87900feb..13d4b7af 100644 --- a/inc/ti/version.h +++ b/inc/ti/version.h @@ -6,7 +6,7 @@ #define TI_VERSION_MAJOR 1 #define TI_VERSION_MINOR 8 -#define TI_VERSION_PATCH 5 +#define TI_VERSION_PATCH 6 /* The syntax version is used to test compatibility with functions * using the `ti_nodes_check_syntax()` function */ @@ -25,7 +25,7 @@ * "-rc0" * "" */ -#define TI_VERSION_PRE_RELEASE "" +#define TI_VERSION_PRE_RELEASE "-alpha0" #define TI_MAINTAINER \ "Jeroen van der Heijden " diff --git a/itest/test_type.py b/itest/test_type.py index 7c1768f3..3adaedbf 100755 --- a/itest/test_type.py +++ b/itest/test_type.py @@ -2406,9 +2406,14 @@ async def test_idx_type(self, client): [ timeit(type_all('T1').len()), // fast timeit(type_all('V').len()), // slow + timeit(type_count('T1')), // fast + timeit(type_count('V')), // slow ]; """) self.assertLess(res[0]['time'], res[1]['time']) + self.assertLess(res[2]['time'], res[3]['time']) + self.assertEqual(res[0]['data'], res[2]['data']) + self.assertEqual(res[1]['data'], res[3]['data']) if __name__ == '__main__':