Skip to content

Commit 9cbc065

Browse files
author
Achyut Kumar M
committed
remove unused code and add logs for better readibilty while debugging
1 parent 4211217 commit 9cbc065

File tree

1 file changed

+16
-74
lines changed

1 file changed

+16
-74
lines changed

GoInfoGame/GoInfoGame/DataBase/DatabaseConnector.swift

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -130,53 +130,7 @@ class DatabaseConnector {
130130
print("Error clearing DB")
131131
}
132132
}
133-
/**
134-
Earlier implementation of saveElements. This used to save only the Way type of objects.
135-
This is not used anymore
136-
*/
137-
// func saveElements(_ elements: [OPWay]) {
138-
// do {
139-
// try realm.write {
140-
// for element in elements {
141-
// let realmElement = RealmOPElement()
142-
// realmElement.id = element.id
143-
// realmElement.isInteresting = element.isInteresting
144-
// realmElement.isSkippable = element.isSkippable
145-
//
146-
// let realmTags = element.tags.map { tag in
147-
// let realmTag = RealmOPElementTag()
148-
// realmTag.key = tag.key
149-
// realmTag.value = tag.value
150-
// return realmTag
151-
// }
152-
// realmElement.tags.append(objectsIn: realmTags)
153-
//
154-
// if let meta = element.meta {
155-
// let realmMeta = RealmOPMeta()
156-
// realmMeta.version = meta.version
157-
// realmMeta.timestamp = meta.timestamp
158-
// realmMeta.changeset = meta.changeset
159-
// realmMeta.userId = meta.userId
160-
// realmMeta.username = meta.username
161-
// realmElement.meta = realmMeta
162-
// } else {
163-
// realmElement.meta = RealmOPMeta()
164-
// }
165-
//
166-
// if !element.nodes.isEmpty {
167-
// realmElement.nodes.append(objectsIn: element.nodes)
168-
// }
169-
// let geometry = RealmOPGeometry(geometry: element.geometry)
170-
// realmElement.geometry.append(geometry)
171-
// realm.add(realmElement, update: .modified)
172-
// }
173-
//
174-
//
175-
// }
176-
// } catch {
177-
// print("Error saving elements to Realm: \(error)")
178-
// }
179-
// }
133+
180134
func saveElements(_ elements: [OSMWay]) {
181135
do {
182136
try realm.write {
@@ -264,7 +218,7 @@ class DatabaseConnector {
264218
@param id: String value of the node ID
265219
@return StoredNode
266220
*/
267-
func getNode(id:Int, version: StoredWayVersion) -> StoredNode? {
221+
func getNode(id:Int, version: StoredNodeVersion) -> StoredNode? {
268222
let compoundId = "\(id)-\(version.rawValue)"
269223
return realm.object(ofType: StoredNode.self, forPrimaryKey: compoundId)
270224
}
@@ -293,26 +247,7 @@ class DatabaseConnector {
293247
@param id: String value of the way ID
294248
@param tags `[String:String]` map of the added tags
295249
@return `StoredWay`
296-
*/
297-
// func addWayTags(id: String, tags:[String:String]) -> StoredWay? {
298-
// guard let theWay = getWay(id: id) else { return nil }
299-
//
300-
//
301-
// do {
302-
// try realm.write {
303-
// theWay.isOriginal = false
304-
// tags.forEach { (key: String, value: String) in
305-
// theWay.tags.setValue(value, forKey: key)
306-
// }
307-
// }
308-
// }
309-
// catch {
310-
// print("Error while writing tags")
311-
// }
312-
// return theWay
313-
// }
314-
315-
250+
*/
316251
func addWayTags(id: String, tags: [String: String]) -> StoredWay? {
317252
let intId = Int(id) ?? -1
318253

@@ -372,25 +307,28 @@ class DatabaseConnector {
372307
*/
373308
func addNodeTags(id: String, tags: [String: String]) -> StoredNode? {
374309
let intId = Int(id) ?? -1
310+
print("🟣 addNodeTags called for id: \(intId) with tags: \(tags)")
375311

376-
// Step 1: Try to get the editable copy first
377312
if let editable = getNode(id: intId, version: .edited) {
313+
print("✏️ Editable node exists: \(editable.compoundId)")
378314
do {
379315
try realm.write {
380316
tags.forEach { editable.tags[$0.key] = $0.value }
381317
}
318+
print("✅ Updated editable node.")
382319
} catch {
383-
print("Error while writing node tags")
320+
print("Error while writing node tags: \(error)")
384321
}
385322
return editable
386323
}
387324

388-
// Step 2: If not found, create from original
389325
guard let original = getNode(id: intId, version: .original) else {
390-
print("❌ Original node not found")
326+
print("❌ Original node not found for id: \(intId)")
391327
return nil
392328
}
393329

330+
print("📄 Creating editable copy from original: \(original.compoundId)")
331+
394332
let copy = StoredNode()
395333
copy.id = original.id
396334
copy.version = original.version
@@ -399,25 +337,29 @@ class DatabaseConnector {
399337
copy.isOriginal = false
400338
copy.generateCompoundId()
401339

340+
print("🛠️ New compoundId: \(copy.compoundId)")
341+
402342
original.tags.forEach { entry in
403343
copy.tags[entry.key] = entry.value
404344
}
405345

406-
// Step 3: Apply new tags
407346
tags.forEach { copy.tags[$0.key] = $0.value }
408347

409348
do {
410349
try realm.write {
411350
realm.add(copy)
412351
}
352+
print("✅ Editable node copy saved to DB: \(copy.compoundId)")
413353
} catch {
414-
print("Error while saving editable node copy")
354+
print("Error while saving editable node copy: \(error)")
415355
}
416356

417357
return copy
418358
}
419359

420360

361+
362+
421363

422364

423365
/**

0 commit comments

Comments
 (0)