Skip to content

Commit 2e10ab9

Browse files
committed
refactor: primary_key_or
Signed-off-by: ekexium <[email protected]>
1 parent 624a53b commit 2e10ab9

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/transaction/buffer.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ impl InnerBuffer {
2727
self.entry_map.insert(key, entry);
2828
}
2929

30-
pub fn get_primary_key_or_insert(&mut self, key: &Key) -> &Key {
31-
self.primary_key.get_or_insert(key.clone())
30+
/// Set the primary key if it is not set
31+
pub fn primary_key_or(&mut self, key: &Key) {
32+
self.primary_key.get_or_insert(key.clone());
3233
}
3334
}
3435

@@ -49,13 +50,9 @@ impl Buffer {
4950
self.inner.lock().await.primary_key.clone()
5051
}
5152

52-
/// Get the primary key of the buffer, if not exists, use `key` as the primary key.
53-
pub async fn get_primary_key_or_insert(&self, key: &Key) -> Key {
54-
self.inner
55-
.lock()
56-
.await
57-
.get_primary_key_or_insert(key)
58-
.clone()
53+
/// Set the primary key if it is not set
54+
pub async fn primary_key_or(&self, key: &Key) {
55+
self.inner.lock().await.primary_key_or(key);
5956
}
6057

6158
/// Get a value from the buffer.

src/transaction/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<PdC: PdClient> Transaction<PdC> {
674674
let pairs = plan.execute().await;
675675

676676
// primary key will be set here if needed
677-
self.buffer.get_primary_key_or_insert(&first_key).await;
677+
self.buffer.primary_key_or(&first_key).await;
678678

679679
self.start_auto_heartbeat().await;
680680

0 commit comments

Comments
 (0)