Skip to content

Commit 56363c9

Browse files
committed
feat: add option in settings to clear v1/v2 database index
1 parent 635fe83 commit 56363c9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Sushitrain/App.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ struct SushitrainApp: App {
4444
Log.info("Logging enabled: \(enableLogging)")
4545

4646
let client = SushitrainNewClient(configPath, documentsPath, enableLogging)!
47+
48+
// Optionally clear v1 and/or v2 index
49+
let clearV1Index = UserDefaults.standard.bool(forKey: "clearV1Index")
50+
let clearV2Index = UserDefaults.standard.bool(forKey: "clearV2Index")
51+
if clearV1Index {
52+
Log.info("Deleting v1 index...")
53+
do {
54+
try client.clearV1Index()
55+
UserDefaults.standard.setValue(false, forKey: "clearV1Index")
56+
}
57+
catch {
58+
Log.warn("Failed to delete v1 index: " + error.localizedDescription)
59+
}
60+
}
61+
if clearV2Index {
62+
Log.info("Deleting v2 index...")
63+
do {
64+
try client.clearV2Index()
65+
UserDefaults.standard.setValue(false, forKey: "clearV2Index")
66+
}
67+
catch {
68+
Log.warn("Failed to delete v2 index: " + error.localizedDescription)
69+
}
70+
}
71+
4772
let appState = AppState(client: client, documentsDirectory: documentsDirectory, configDirectory: configDirectory)
4873
self.appState = appState
4974

Sushitrain/Settings.bundle/Root.plist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@
2222
<key>DefaultValue</key>
2323
<false/>
2424
</dict>
25+
<dict>
26+
<key>Type</key>
27+
<string>PSToggleSwitchSpecifier</string>
28+
<key>Title</key>
29+
<string>Delete v1 index</string>
30+
<key>Key</key>
31+
<string>clearV1Index</string>
32+
<key>DefaultValue</key>
33+
<false/>
34+
</dict>
35+
<dict>
36+
<key>Type</key>
37+
<string>PSToggleSwitchSpecifier</string>
38+
<key>Title</key>
39+
<string>Delete v2 index</string>
40+
<key>Key</key>
41+
<string>clearV2Index</string>
42+
<key>DefaultValue</key>
43+
<false/>
44+
</dict>
2545
</array>
2646
</dict>
2747
</plist>

SushitrainCore/src/sushitrain.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,3 +1338,15 @@ func ShortDeviceID(devID string) string {
13381338
}
13391339
return did.Short().String()
13401340
}
1341+
1342+
func (c *Client) ClearV1Index() error {
1343+
dbPath := locations.Get(locations.LegacyDatabase)
1344+
Logger.Warnf("Removing v1 index at %s", dbPath)
1345+
return os.RemoveAll(dbPath)
1346+
}
1347+
1348+
func (c *Client) ClearV2Index() error {
1349+
dbPath := locations.Get(locations.Database)
1350+
Logger.Warnf("Removing v2 index at %s", dbPath)
1351+
return os.RemoveAll(dbPath)
1352+
}

0 commit comments

Comments
 (0)