Remove script no longer in use
[yaz-moved-to-github.git] / src / zoom-record-cache.c
index d9d3765..957e8f9 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -49,16 +49,6 @@ struct ZOOM_record_cache_p {
     ZOOM_record_cache next;
 };
 
-
-static int strcmp_null(const char *v1, const char *v2)
-{
-    if (!v1 && !v2)
-        return 0;
-    if (!v1 || !v2)
-        return -1;
-    return strcmp(v1, v2);
-}
-
 static size_t record_hash(int pos)
 {
     if (pos < 0)
@@ -66,11 +56,13 @@ static size_t record_hash(int pos)
     return pos % RECORD_HASH_SIZE;
 }
 
-void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
-                           int pos,
-                           const char *syntax, const char *elementSetName,
-                           const char *schema,
-                           Z_SRW_diagnostic *diag)
+static ZOOM_record record_cache_add(ZOOM_resultset r,
+                                    Z_NamePlusRecord *npr,
+                                    int pos,
+                                    const char *syntax,
+                                    const char *elementSetName,
+                                    const char *schema,
+                                    Z_SRW_diagnostic *diag)
 {
     ZOOM_record_cache rc = 0;
 
@@ -80,9 +72,9 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
     for (rc = r->record_hash[record_hash(pos)]; rc; rc = rc->next)
     {
         if (pos == rc->pos
-            && strcmp_null(r->schema, rc->schema) == 0
-            && strcmp_null(elementSetName,rc->elementSetName) == 0
-            && strcmp_null(syntax, rc->syntax) == 0)
+            && yaz_strcmp_null(schema, rc->schema) == 0
+            && yaz_strcmp_null(elementSetName,rc->elementSetName) == 0
+            && yaz_strcmp_null(syntax, rc->syntax) == 0)
             break;
     }
     if (!rc)
@@ -99,12 +91,14 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
 
         rc->syntax = odr_strdup_null(r->odr, syntax);
 
-        rc->schema = odr_strdup_null(r->odr, r->schema);
+        rc->schema = odr_strdup_null(r->odr, schema);
 
         rc->pos = pos;
         rc->next = r->record_hash[record_hash(pos)];
         r->record_hash[record_hash(pos)] = rc;
+
     }
+
     rc->rec.npr = npr;
     rc->rec.schema = odr_strdup_null(r->odr, schema);
     rc->rec.diag_set = 0;
@@ -124,11 +118,23 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
         rc->rec.diag_message = odr_strdup_null(r->odr, diag->message);
         rc->rec.diag_details = odr_strdup_null(r->odr, diag->details);
     }
+    return &rc->rec;
 }
 
-ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
-                                     const char *syntax,
-                                     const char *elementSetName)
+void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
+                           int pos,
+                           const char *syntax, const char *elementSetName,
+                           const char *schema,
+                           Z_SRW_diagnostic *diag)
+{
+    record_cache_add(r, npr, pos, syntax, elementSetName, schema, diag);
+    ZOOM_memcached_add(r, npr, pos, syntax, elementSetName, schema, diag);
+}
+
+ZOOM_record ZOOM_record_cache_lookup_i(ZOOM_resultset r, int pos,
+                                       const char *syntax,
+                                       const char *elementSetName,
+                                       const char *schema)
 {
     ZOOM_record_cache rc;
 
@@ -136,11 +142,11 @@ ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
     {
         if (pos == rc->pos)
         {
-            if (strcmp_null(r->schema, rc->schema))
+            if (yaz_strcmp_null(schema, rc->schema))
                 continue;
-            if (strcmp_null(elementSetName,rc->elementSetName))
+            if (yaz_strcmp_null(elementSetName,rc->elementSetName))
                 continue;
-            if (strcmp_null(syntax, rc->syntax))
+            if (yaz_strcmp_null(syntax, rc->syntax))
                 continue;
             return &rc->rec;
         }
@@ -148,6 +154,27 @@ ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
     return 0;
 }
 
+ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos,
+                                     const char *syntax,
+                                     const char *elementSetName,
+                                     const char *schema)
+{
+    Z_NamePlusRecord *npr;
+    ZOOM_record rec = ZOOM_record_cache_lookup_i(r, pos, syntax,
+                                                 elementSetName, schema);
+    if (rec)
+    {
+        ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD);
+        ZOOM_connection_put_event(r->connection, event);
+        return rec;
+    }
+    npr = ZOOM_memcached_lookup(r, pos, syntax, elementSetName, schema);
+    if (npr)
+        return record_cache_add(r, npr, pos, syntax, elementSetName,
+                                schema, 0);
+    return 0;
+}
+
 ZOOM_API(ZOOM_record)
     ZOOM_record_clone(ZOOM_record srec)
 {