+void extract_flush_record_keys2(ZebraHandle zh, zint sysno,
+ zebra_rec_keys_t ins_keys, zint ins_rank,
+ zebra_rec_keys_t del_keys, zint del_rank)
+{
+ ZebraExplainInfo zei = zh->reg->zei;
+ int normal = 0;
+ int optimized = 0;
+
+ if (!zh->reg->key_block)
+ {
+ int mem = 1024*1024 * atoi( res_get_def( zh->res, "memmax", "8"));
+ const char *key_tmp_dir = res_get_def (zh->res, "keyTmpDir", ".");
+ int use_threads = atoi(res_get_def (zh->res, "threads", "1"));
+ zh->reg->key_block = key_block_create(mem, key_tmp_dir, use_threads);
+ }
+
+ if (ins_keys)
+ {
+ extract_rec_keys_adjust(zh, 1, ins_keys);
+ if (!del_keys)
+ zebraExplain_recordCountIncrement (zei, 1);
+ zebra_rec_keys_rewind(ins_keys);
+ }
+ if (del_keys)
+ {
+ extract_rec_keys_adjust(zh, 0, del_keys);
+ if (!ins_keys)
+ zebraExplain_recordCountIncrement (zei, -1);
+ zebra_rec_keys_rewind(del_keys);
+ }
+
+ while (1)
+ {
+ size_t del_slen;
+ const char *del_str;
+ struct it_key del_key_in;
+ int del = 0;
+
+ size_t ins_slen;
+ const char *ins_str;
+ struct it_key ins_key_in;
+ int ins = 0;
+
+ if (del_keys)
+ del = zebra_rec_keys_read(del_keys, &del_str, &del_slen,
+ &del_key_in);
+ if (ins_keys)
+ ins = zebra_rec_keys_read(ins_keys, &ins_str, &ins_slen,
+ &ins_key_in);
+
+ if (del && ins && ins_rank == del_rank
+ && !key_compare(&del_key_in, &ins_key_in)
+ && ins_slen == del_slen && !memcmp(del_str, ins_str, del_slen))
+ {
+ optimized++;
+ continue;
+ }
+ if (!del && !ins)
+ break;
+
+ normal++;
+ if (del)
+ key_block_write(zh->reg->key_block, sysno,
+ &del_key_in, 0, del_str, del_slen,
+ del_rank, zh->m_staticrank);
+ if (ins)
+ key_block_write(zh->reg->key_block, sysno,
+ &ins_key_in, 1, ins_str, ins_slen,
+ ins_rank, zh->m_staticrank);
+ }
+ yaz_log(YLOG_LOG, "normal=%d optimized=%d", normal, optimized);
+}
+