[DUP-1] Five DataStoreProtocol implementations are ~75% copy-paste (~942 lines → ~120-line generic helper) #36

Closed
opened 2026-11-14 18:28:59 +01:00 by amiryahaya · 1 comment
Owner

Finding

client/signing_key/access_token/login_attempt/certificate_request data stores share an identical skeleton (init, save+transaction, delete, exec(:reset), wrap_with, ensure_table_exists incl. wait_for_tables, generate_id); only table name, attributes, record tuple, to_struct and find patterns differ (diff-verified: 34-66 changed lines between siblings).

Evidence

  • lib/mdid_ws/oauth/client_data_store.ex (157), signing_key_data_store.ex (152), access_token_data_store.ex (163), lib/mdid_ws/auth/login_attempt_data_store.ex (183), lib/mdid_ws/cert_management/certificate_request_data_store.ex (287)

Impact

~450-500 removable lines; 5 divergent copies of transaction/wait logic; schema changes touch 5 places by hand (the certificate_request legacy migration already demonstrates the pain).

Fix

  • Extract a generic Mnesia store helper (table + attributes + struct ctor + match patterns as data) and reduce each module to a ~35-line config

Line numbers refer to the initial import commit 282cb11. Source: comprehensive audit, 2026-11-12 (first review of this codebase).

## Finding client/signing_key/access_token/login_attempt/certificate_request data stores share an identical skeleton (init, save+transaction, delete, exec(:reset), wrap_with, ensure_table_exists incl. wait_for_tables, generate_id); only table name, attributes, record tuple, to_struct and find patterns differ (diff-verified: 34-66 changed lines between siblings). ## Evidence - `lib/mdid_ws/oauth/client_data_store.ex` (157), `signing_key_data_store.ex` (152), `access_token_data_store.ex` (163), `lib/mdid_ws/auth/login_attempt_data_store.ex` (183), `lib/mdid_ws/cert_management/certificate_request_data_store.ex` (287) ## Impact ~450-500 removable lines; 5 divergent copies of transaction/wait logic; schema changes touch 5 places by hand (the certificate_request legacy migration already demonstrates the pain). ## Fix - [ ] Extract a generic Mnesia store helper (table + attributes + struct ctor + match patterns as data) and reduce each module to a ~35-line config _Line numbers refer to the initial import commit `282cb11`. Source: comprehensive audit, 2026-11-12 (first review of this codebase)._
Author
Owner

Verified fixed on main (1b6216b): five stores are configuration over MdidWs.MnesiaStore (B6, PR #59).

Verified fixed on main (1b6216b): five stores are configuration over MdidWs.MnesiaStore (B6, PR #59).
Sign in to join this conversation.
No description provided.