From 9674ede85ad5c2e6dcc6d47e78ffc60c92b90504 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Sun, 22 Jul 2018 17:52:09 +0800 Subject: [PATCH] Streams: skip master fileds only when we are going forward in streamIteratorGetID --- src/t_stream.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 201509c7..15a41bed 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -548,13 +548,16 @@ int streamIteratorGetID(streamIterator *si, streamID *id, int64_t *numfields) { si->master_fields_count = lpGetInteger(si->lp_ele); si->lp_ele = lpNext(si->lp,si->lp_ele); /* Seek first field. */ si->master_fields_start = si->lp_ele; - /* Skip master fileds to seek the first entry. */ - for (uint64_t i = 0; i < si->master_fields_count; i++) - si->lp_ele = lpNext(si->lp,si->lp_ele); - /* We are now pointing the zero term of the master entry. If + /* We are now pointing the start filed of the master entry. If * we are iterating in reverse order, we need to seek the * end of the listpack. */ - if (si->rev) si->lp_ele = lpLast(si->lp); + if (si->rev) { + si->lp_ele = lpLast(si->lp); + } else { + /* Skip master fileds to seek the first entry. */ + for (uint64_t i = 0; i < si->master_fields_count; i++) + si->lp_ele = lpNext(si->lp,si->lp_ele); + } } else if (si->rev) { /* If we are itereating in the reverse order, and this is not * the first entry emitted for this listpack, then we already