fix: order_by_metadata for responses from cache (#8514)

### **PR Type**
Bug fix


___

### **Description**
- Preserve `order_by_metadata` in cached responses

- Clone metadata from first search result

- Align cache response fields with live responses


___

### Diagram Walkthrough


```mermaid
flowchart LR
  A["Search responses (live)"] -- "first().order_by_metadata.clone()" --> B["Cache response.order_by_metadata"]
  A -- "first().order_by" --> C["Cache response.order_by"]
  D["Cache stats"] -- "compute ratio" --> E["Cache response.result_cache_ratio"]
```



<details> <summary><h3> File Walkthrough</h3></summary>

<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Bug
fix</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>mod.rs</strong><dd><code>Propagate `order_by_metadata`
into cache response</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </dd></summary>
<hr>

src/service/search/cache/mod.rs

<ul><li>Set <code>cache_response.order_by_metadata</code> from first
result<br> <li> Clone metadata to avoid ownership issues<br> <li> Keep
default when no results available</ul>


</details>


  </td>
<td><a
href="https://github.com/openobserve/openobserve/pull/8514/files#diff-f07bfacc0501b9c234e64b16c1dd8eb0ae8fcbe231f90c81fed72bcc94946f74">+4/-0</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></td></tr></tr></tbody></table>

</details>

___

Co-authored-by: Subhra264 <chakrabortysubhradeep556@gmail.com>
This commit is contained in:
Loakesh Indiran
2025-09-18 14:49:24 +05:30
committed by GitHub
co-authored by Subhra264
parent d40b6afc2e
commit 373bbf4bdb
+4
View File
@@ -642,6 +642,10 @@ pub fn merge_response(
.first()
.map(|res| res.order_by)
.unwrap_or_default();
cache_response.order_by_metadata = search_response
.first()
.map(|res| res.order_by_metadata.clone())
.unwrap_or_default();
cache_response.result_cache_ratio = (((cache_hits_len as f64) * 100_f64)
/ ((result_cache_len + cache_hits_len) as f64))
as usize;