From fb5213566cefc1afb8af9651baaf02e15db7c07f Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Wed, 20 May 2026 17:06:42 +0200 Subject: [PATCH 1/3] Type count from cache if possible --- CHANGELOG.md | 4 ++++ inc/ti/fn/fntypecount.h | 3 ++- inc/ti/version.h | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fba3cb47..882494cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v1.8.6-alpha0 + +* Read `type_count(..)` from cache if available. + # 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..7cab4c18 100644 --- a/inc/ti/fn/fntypecount.h +++ b/inc/ti/fn/fntypecount.h @@ -16,7 +16,8 @@ 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 */ + n = type->t_cache ? type->t_cache->n : ti_query_count_type(query, type); 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 " From 66ee667eca462703ca9330126fe961e03892bd7c Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 21 May 2026 11:22:39 +0200 Subject: [PATCH 2/3] test type --- CHANGELOG.md | 2 +- inc/ti/fn/fntypecount.h | 15 ++++++++++++++- itest/test_type.py | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 882494cf..ee02454d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # v1.8.6-alpha0 -* Read `type_count(..)` from cache if available. +* Read `type_count(..)` from cache if available, pr #443. # v1.8.5 diff --git a/inc/ti/fn/fntypecount.h b/inc/ti/fn/fntypecount.h index 7cab4c18..f9087674 100644 --- a/inc/ti/fn/fntypecount.h +++ b/inc/ti/fn/fntypecount.h @@ -17,7 +17,20 @@ static int do__f_type_count(ti_query_t * query, cleri_node_t * nd, ex_t * e) return ti_raw_err_not_found((ti_raw_t *) query->rval, "type", e); /* use cache if available */ - n = type->t_cache ? type->t_cache->n : ti_query_count_type(query, type); + 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/itest/test_type.py b/itest/test_type.py index 7c1768f3..b83a107b 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], res[2]) + self.assertEqual(res[1], res[3]) if __name__ == '__main__': From b44910a4cac8d8fd620263abb31199e715ee1ee6 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 21 May 2026 16:48:57 +0200 Subject: [PATCH 3/3] Test fix --- itest/test_type.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/itest/test_type.py b/itest/test_type.py index b83a107b..3adaedbf 100755 --- a/itest/test_type.py +++ b/itest/test_type.py @@ -2412,8 +2412,8 @@ async def test_idx_type(self, client): """) self.assertLess(res[0]['time'], res[1]['time']) self.assertLess(res[2]['time'], res[3]['time']) - self.assertEqual(res[0], res[2]) - self.assertEqual(res[1], res[3]) + self.assertEqual(res[0]['data'], res[2]['data']) + self.assertEqual(res[1]['data'], res[3]['data']) if __name__ == '__main__':