Add reclist rewind function
[pazpar2-moved-to-github.git] / src / reclists.c
index f07a2cb..103eefd 100644 (file)
@@ -342,6 +342,12 @@ void reclist_leave(struct reclist *l)
         l->sorted_ptr = l->sorted_list;
 }
 
+void reclist_rewind(struct reclist *l)
+{
+    if (l)
+        l->sorted_ptr = l->sorted_list;
+}
+
 
 struct reclist *reclist_create(NMEM nmem)
 {
@@ -496,21 +502,19 @@ struct record_cluster *reclist_insert(struct reclist *l,
                 // We found a matching record. Merge them
                 if (!strcmp(merge_key, mkr->value))
                 {
-                    struct record **re;
-
                     rb = *p;
-                    for (re = &rb->record->records; *re; re = &(*re)->next)
+                    if (!cluster)
                     {
-                        if ((*re)->client == record->client &&
-                            record_compare(record, *re, service))
+                        struct record **re;
+                        for (re = &rb->record->records; *re; re = &(*re)->next)
                         {
-                            yaz_mutex_leave(l->mutex);
-                            return 0;
+                            if ((*re)->client == record->client &&
+                                record_compare(record, *re, service))
+                            {
+                                yaz_mutex_leave(l->mutex);
+                                return 0;
+                            }
                         }
-                    }
-
-                    if (!cluster)
-                    {
                         cluster = rb->record;
                         *re = record;
                         record->next = 0;