Skip to content

Commit de36083

Browse files
committed
refactor(sidebar): derive recent entry id from Entry.id, cover clearAll
Remove private entryId helper — push now constructs Entry first and deduplicates via Entry.id, keeping a single identity source. Add ClearAll test covering two keys (nil and string database).
1 parent 908a15b commit de36083

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

TablePro/Core/Storage/RecentTablesStore.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,10 @@ final class RecentTablesStore {
2828

2929
func push(connectionID: UUID, database: String?, table: TableInfo) {
3030
let key = Key(connectionID: connectionID, database: database)
31+
let entry = Entry(name: table.name, schema: table.schema, type: table.type)
3132
var list = entriesByKey[key] ?? []
32-
let newEntryId = entryId(name: table.name, schema: table.schema)
33-
list.removeAll { $0.id == newEntryId }
34-
list.insert(
35-
Entry(
36-
name: table.name,
37-
schema: table.schema,
38-
type: table.type
39-
),
40-
at: 0
41-
)
33+
list.removeAll { $0.id == entry.id }
34+
list.insert(entry, at: 0)
4235
if list.count > cap {
4336
list = Array(list.prefix(cap))
4437
}
@@ -61,8 +54,4 @@ final class RecentTablesStore {
6154
}
6255

6356
var cappedSize: Int { cap }
64-
65-
private func entryId(name: String, schema: String?) -> String {
66-
schema.map { "\($0).\(name)" } ?? name
67-
}
6857
}

TableProTests/Storage/RecentTablesStoreTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,16 @@ struct RecentTablesStoreTests {
9292
#expect(store.entries(connectionID: conn, database: nil).map(\.name) == ["sqlite_table"])
9393
#expect(store.entries(connectionID: conn, database: "postgres").map(\.name) == ["pg_table"])
9494
}
95+
96+
@Test("ClearAll empties every key")
97+
func clearAllEmptiesEveryKey() {
98+
let store = makeStore()
99+
let connA = UUID()
100+
let connB = UUID()
101+
store.push(connectionID: connA, database: "db", table: makeTable("a"))
102+
store.push(connectionID: connB, database: nil, table: makeTable("b"))
103+
store.clearAll()
104+
#expect(store.entries(connectionID: connA, database: "db").isEmpty)
105+
#expect(store.entries(connectionID: connB, database: nil).isEmpty)
106+
}
95107
}

0 commit comments

Comments
 (0)