Skip to content

refactor: replace DeviceRow positional tuple with named struct - #434

Merged
jlucaso1 merged 1 commit into
mainfrom
refactor/device-row-named-struct
Mar 24, 2026
Merged

refactor: replace DeviceRow positional tuple with named struct#434
jlucaso1 merged 1 commit into
mainfrom
refactor/device-row-named-struct

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the 19-element positional tuple DeviceRow with a #[derive(Queryable)] named struct
  • Fields accessed by name (row.lid, row.push_name) instead of position in a tuple destructure

This reduces the risk of field mix-ups when adding new columns to the device table (e.g., the upcoming nct_salt column in #433).

Test plan

  • cargo clippy --all --tests — clean
  • cargo test -p whatsapp-rust-sqlite-storage — all 19 tests pass

Summary by CodeRabbit

  • Refactor
    • Internal improvements to device data handling and storage code for better maintainability.

Replace the 19-element positional tuple with a Diesel Queryable struct
so fields are accessed by name (row.lid) instead of position. This
reduces the risk of mix-ups when adding new columns to the device table.
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3931dc5d-d673-479b-95e9-e9f5d89558a8

📥 Commits

Reviewing files that changed from the base of the PR and between b4fdac0 and 387eda3.

📒 Files selected for processing (1)
  • storages/sqlite-storage/src/sqlite_store.rs

📝 Walkthrough

Walkthrough

Refactored the DeviceRow type from a positional tuple struct to a named struct using #[derive(Queryable)], with explicit fields matching schema column order. Updated load_device_data_for_device to use pattern-matching and named field access instead of tuple destructuring, maintaining equivalent functionality.

Changes

Cohort / File(s) Summary
DeviceRow Type Conversion
storages/sqlite-storage/src/sqlite_store.rs
Converted DeviceRow from tuple-based struct to named struct with explicit fields (id, lid, pn, noise key, account, properties, versions, routing info). Refactored load_device_data_for_device function to replace tuple destructuring with pattern-matching on named fields and updated all field access paths (e.g., row.pn, row.lid, row.noise_key) throughout field parsing and CoreDevice construction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A tuple hops away, named fields now here,
Each field stands clear, no more unclear,
The row reads proud with names so bright,
From schema to struct—clarity takes flight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: refactoring DeviceRow from a positional tuple to a named struct, which is the primary objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/device-row-named-struct

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

🐰 Bencher Report

Branchrefactor/device-row-named-struct
Testbedubuntu-latest

🚨 1 Alert

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
libsignal_benchmark::session_optimization_group::bench_decrypt_with_previous_session previous_session:setup_with_archived_sessions()Instructions
instructions x 1e3
📈 plot
🚷 threshold
🚨 alert (🔔)
47.13 x 1e3
(+10.63%)Baseline: 42.60 x 1e3
44.73 x 1e3
(105.36%)

Click to view all benchmark results
BenchmarkInstructionsBenchmark Result
instructions
(Result Δ%)
Upper Boundary
instructions
(Limit %)
binary_benchmark::attr_parser_group::bench_attr_parser attr_lookup:setup_attr_marshaled()📈 view plot
🚷 view threshold
6,197.00
(-6.21%)Baseline: 6,607.66
6,938.04
(89.32%)
binary_benchmark::child_iteration_group::bench_get_children_by_tag📈 view plot
🚷 view threshold
524,304.00
(-29.87%)Baseline: 747,598.43
784,978.35
(66.79%)
binary_benchmark::jid_optimization_group::bench_jid_to_owned_access jid_access:setup_jid_heavy_marshaled()📈 view plot
🚷 view threshold
20,868.00
(-6.45%)Baseline: 22,306.60
23,421.93
(89.10%)
binary_benchmark::marshal_group::bench_marshal_allocating📈 view plot
🚷 view threshold
98,202.00
(-18.80%)Baseline: 120,941.07
126,988.13
(77.33%)
binary_benchmark::marshal_group::bench_marshal_auto_allocating📈 view plot
🚷 view threshold
98,230.00
(-11.69%)Baseline: 111,232.08
116,793.69
(84.11%)
binary_benchmark::marshal_group::bench_marshal_auto_huge_bytes_allocating📈 view plot
🚷 view threshold
532,948.00
(-0.13%)Baseline: 533,625.36
560,306.63
(95.12%)
binary_benchmark::marshal_group::bench_marshal_auto_long_string📈 view plot
🚷 view threshold
15,870.00
(-5.49%)Baseline: 16,792.70
17,632.34
(90.01%)
binary_benchmark::marshal_group::bench_marshal_auto_many_children_allocating📈 view plot
🚷 view threshold
14,715,201.00
(-9.26%)Baseline: 16,217,395.06
17,028,264.81
(86.42%)
binary_benchmark::marshal_group::bench_marshal_exact_allocating📈 view plot
🚷 view threshold
118,358.00
(-23.36%)Baseline: 154,438.92
162,160.87
(72.99%)
binary_benchmark::marshal_group::bench_marshal_exact_huge_bytes_allocating📈 view plot
🚷 view threshold
534,378.00
(-0.12%)Baseline: 535,044.62
561,796.86
(95.12%)
binary_benchmark::marshal_group::bench_marshal_exact_long_string📈 view plot
🚷 view threshold
17,919.00
(-4.91%)Baseline: 18,844.41
19,786.63
(90.56%)
binary_benchmark::marshal_group::bench_marshal_exact_many_children_allocating📈 view plot
🚷 view threshold
28,066,347.00
(-24.48%)Baseline: 37,165,894.81
39,024,189.55
(71.92%)
binary_benchmark::marshal_group::bench_marshal_huge_bytes_allocating📈 view plot
🚷 view threshold
533,387.00
(-0.13%)Baseline: 534,064.36
560,767.58
(95.12%)
binary_benchmark::marshal_group::bench_marshal_long_string📈 view plot
🚷 view threshold
15,843.00
(-8.34%)Baseline: 17,285.20
18,149.46
(87.29%)
binary_benchmark::marshal_group::bench_marshal_many_children_allocating📈 view plot
🚷 view threshold
14,716,627.00
(-9.26%)Baseline: 16,218,462.70
17,029,385.84
(86.42%)
binary_benchmark::marshal_group::bench_marshal_reusing_buffer📈 view plot
🚷 view threshold
107,945.00
(-15.01%)Baseline: 127,014.06
133,364.76
(80.94%)
binary_benchmark::marshal_group::bench_marshal_reusing_buffer_vec_writer📈 view plot
🚷 view threshold
98,302.00
(-11.68%)Baseline: 111,304.08
116,869.29
(84.11%)
binary_benchmark::roundtrip_group::bench_roundtrip large:setup_large_marshaled()📈 view plot
🚷 view threshold
90,974.00
(-5.99%)Baseline: 96,768.28
101,606.69
(89.54%)
binary_benchmark::roundtrip_group::bench_roundtrip small:setup_small_marshaled()📈 view plot
🚷 view threshold
7,378.00
(-3.86%)Baseline: 7,674.55
8,058.28
(91.56%)
binary_benchmark::roundtrip_group::bench_roundtrip_auto large:setup_large_marshaled()📈 view plot
🚷 view threshold
91,005.00
(-2.10%)Baseline: 92,956.96
97,604.81
(93.24%)
binary_benchmark::roundtrip_group::bench_roundtrip_auto small:setup_small_marshaled()📈 view plot
🚷 view threshold
7,401.00
(+0.43%)Baseline: 7,369.65
7,738.13
(95.64%)
binary_benchmark::roundtrip_group::bench_roundtrip_exact large:setup_large_marshaled()📈 view plot
🚷 view threshold
106,790.00
(-1.80%)Baseline: 108,741.96
114,179.06
(93.53%)
binary_benchmark::roundtrip_group::bench_roundtrip_exact small:setup_small_marshaled()📈 view plot
🚷 view threshold
8,913.00
(+0.35%)Baseline: 8,881.65
9,325.73
(95.57%)
binary_benchmark::unmarshal_group::bench_unmarshal large:setup_large_marshaled()📈 view plot
🚷 view threshold
41,989.00
(-8.89%)Baseline: 46,087.54
48,391.92
(86.77%)
binary_benchmark::unmarshal_group::bench_unmarshal small:setup_small_marshaled()📈 view plot
🚷 view threshold
2,717.00
(-4.99%)Baseline: 2,859.74
3,002.73
(90.48%)
binary_benchmark::unpack_group::bench_unpack_compressed📈 view plot
🚷 view threshold
556,092.00
(+2.83%)Baseline: 540,810.30
567,850.82
(97.93%)
binary_benchmark::unpack_group::bench_unpack_uncompressed📈 view plot
🚷 view threshold
771.00
(-0.34%)Baseline: 773.66
812.34
(94.91%)
libsignal_benchmark::conversation_group::bench_full_dm_conversation full:setup_conversation_data()📈 view plot
🚷 view threshold
27,562,866.00
(-0.51%)Baseline: 27,705,513.63
29,090,789.31
(94.75%)
libsignal_benchmark::dm_group::bench_dm_decrypt_first_message decrypt_prekey:setup_dm_with_first_message()📈 view plot
🚷 view threshold
5,544,446.00
(-0.07%)Baseline: 5,548,304.19
5,825,719.40
(95.17%)
libsignal_benchmark::dm_group::bench_dm_encrypt_first_message first_msg:setup_dm_session()📈 view plot
🚷 view threshold
175,119.00
(-1.49%)Baseline: 177,759.45
186,647.42
(93.82%)
libsignal_benchmark::dm_group::bench_dm_encrypt_subsequent_message subsequent:setup_established_dm_session()📈 view plot
🚷 view threshold
175,768.00
(-1.56%)Baseline: 178,553.69
187,481.38
(93.75%)
libsignal_benchmark::dm_group::bench_dm_session_establishment setup:setup_dm_users()📈 view plot
🚷 view threshold
17,352,437.00
(+0.41%)Baseline: 17,281,938.48
18,146,035.40
(95.63%)
libsignal_benchmark::group_messaging_group::bench_group_create_distribution_message create:setup_group_sender()📈 view plot
🚷 view threshold
298,417.00
(+0.63%)Baseline: 296,537.89
311,364.78
(95.84%)
libsignal_benchmark::group_messaging_group::bench_group_decrypt_message decrypt:setup_group_with_encrypted_message()📈 view plot
🚷 view threshold
12,552,348.00
(-0.36%)Baseline: 12,597,128.30
13,226,984.72
(94.90%)
libsignal_benchmark::group_messaging_group::bench_group_encrypt_message encrypt:setup_group_with_distribution()📈 view plot
🚷 view threshold
719,597.00
(+0.44%)Baseline: 716,478.60
752,302.53
(95.65%)
libsignal_benchmark::session_optimization_group::bench_decrypt_with_previous_session previous_session:setup_with_archived_sessions()📈 view plot
🚷 view threshold
🚨 view alert (🔔)
47,129.00
(+10.63%)Baseline: 42,600.25
44,730.26
(105.36%)

libsignal_benchmark::session_optimization_group::bench_message_key_eviction eviction:setup_message_key_eviction()📈 view plot
🚷 view threshold
15,561,842.00
(+0.00%)Baseline: 15,561,751.55
16,339,839.12
(95.24%)
libsignal_benchmark::session_optimization_group::bench_out_of_order_decryption out_of_order:setup_out_of_order_messages()📈 view plot
🚷 view threshold
5,371,271.00
(-2.26%)Baseline: 5,495,303.05
5,770,068.20
(93.09%)
libsignal_benchmark::session_optimization_group::bench_promote_matching_session promote:setup_promote_matching_session()📈 view plot
🚷 view threshold
311,806.00
(-64.92%)Baseline: 888,766.72
933,205.06
(33.41%)
libsignal_benchmark::signature_group::bench_key_generation keygen📈 view plot
🚷 view threshold
2,830,547.00
(+0.21%)Baseline: 2,824,678.63
2,965,912.57
(95.44%)
libsignal_benchmark::signature_group::bench_signature_creation sign:setup_keypair_with_message()📈 view plot
🚷 view threshold
3,452,844.00
(-0.61%)Baseline: 3,474,049.59
3,647,752.07
(94.66%)
libsignal_benchmark::signature_group::bench_signature_verification verify:setup_keypair_with_message()📈 view plot
🚷 view threshold
127,341,018.00
(+1.59%)Baseline: 125,344,627.20
131,611,858.56
(96.75%)
reporting_token_benchmark::content_extraction_group::bench_content_extraction extended:setup_extended_message()📈 view plot
🚷 view threshold
11,804.00
(+0.04%)Baseline: 11,799.46
12,389.43
(95.27%)
reporting_token_benchmark::content_extraction_group::bench_content_extraction simple:setup_simple_message()📈 view plot
🚷 view threshold
3,822.00
(-0.03%)Baseline: 3,823.17
4,014.33
(95.21%)
reporting_token_benchmark::full_generation_group::bench_full_token_generation extended:setup_full_gen_extended()📈 view plot
🚷 view threshold
86,875.00
(-1.12%)Baseline: 87,863.03
92,256.19
(94.17%)
reporting_token_benchmark::full_generation_group::bench_full_token_generation simple:setup_full_gen_simple()📈 view plot
🚷 view threshold
78,914.00
(-1.25%)Baseline: 79,909.19
83,904.65
(94.05%)
reporting_token_benchmark::key_derivation_group::bench_key_derivation📈 view plot
🚷 view threshold
50,375.00
(-1.21%)Baseline: 50,991.21
53,540.77
(94.09%)
reporting_token_benchmark::message_encoding_group::bench_message_encoding extended:setup_extended_message()📈 view plot
🚷 view threshold
5,758.00
(+0.15%)Baseline: 5,749.30
6,036.76
(95.38%)
reporting_token_benchmark::message_encoding_group::bench_message_encoding simple:setup_simple_message()📈 view plot
🚷 view threshold
2,119.00
(+0.03%)Baseline: 2,118.39
2,224.31
(95.27%)
reporting_token_benchmark::token_calculation_group::bench_token_calculation📈 view plot
🚷 view threshold
21,920.00
(+0.02%)Baseline: 21,916.63
23,012.47
(95.25%)
🐰 View full continuous benchmarking report in Bencher

@jlucaso1
jlucaso1 merged commit 1a57769 into main Mar 24, 2026
8 checks passed
@jlucaso1
jlucaso1 deleted the refactor/device-row-named-struct branch March 24, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant