Skip to content

Commit 8464138

Browse files
committed
removed compoundId
removed compoundId which is create with store version. made id as primary key
1 parent 145657d commit 8464138

File tree

4 files changed

+19
-40
lines changed

4 files changed

+19
-40
lines changed

GoInfoGame/GoInfoGame/AppQuestManager.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class AppQuestManager {
3030
n.tags.count != 0
3131
}
3232
let waysFromStorage = dbInstance.getWays().filter{w in w.tags.count != 0 }
33-
let theWay = waysFromStorage.first(where: {$0.id == Int(elementId)})
34-
let theNode = nodesFromStorage.first(where: {$0.id == Int(elementId)})
33+
let theWay = waysFromStorage.first(where: {$0.id == Int64(elementId)})
34+
let theNode = nodesFromStorage.first(where: {$0.id == Int64(elementId)})
3535
let allQuests = QuestsRepository.shared.applicableQuests
3636
// theElement if not equal to nil
3737
if (theNode != nil) {
@@ -56,7 +56,7 @@ class AppQuestManager {
5656
// Create a duplicate of the quest
5757
// Need to add another here.
5858
let duplicateQuest = quest.quest.copyWithElement(element: wayElement!)
59-
let position = dbInstance.getCenterForWay(id: String(wayElement!.id)) ?? CLLocationCoordinate2D()
59+
let position = dbInstance.getCenterForWay(id: wayElement!.id) ?? CLLocationCoordinate2D()
6060
let unit = DisplayUnitWithCoordinate(displayUnit: duplicateQuest.displayUnit, coordinateInfo: position, id: wayElement!.id, isHidden: false)
6161
return unit
6262
}
@@ -69,15 +69,15 @@ class AppQuestManager {
6969
// Fetches all the available quests from Database
7070
func fetchQuestsFromDB() -> [DisplayUnitWithCoordinate] {
7171

72-
let allOriginalNodes = dbInstance.getNodes().filter { $0.isOriginal && $0.tags.count != 0 }
72+
let allOriginalNodes = dbInstance.getNodes().filter {$0.tags.count != 0 }
7373

7474

7575
let nodesFromStorage: [StoredNode] = allOriginalNodes.compactMap { original in
7676
original.tags["ext:gig_complete"] == "yes" ? nil : original
7777
}
7878

7979
let allOriginalWays = dbInstance.getWays().filter {
80-
$0.isOriginal && $0.tags.count != 0
80+
$0.tags.count != 0
8181
}
8282

8383
let waysFromStorage: [StoredWay] = allOriginalWays.compactMap { original in
@@ -119,7 +119,7 @@ class AppQuestManager {
119119
// Create a duplicate of the quest
120120
// Need to add another here.
121121
let duplicateQuest = quest.quest.copyWithElement(element: way)
122-
let position = dbInstance.getCenterForWay(id: String(way.id)) ?? CLLocationCoordinate2D()
122+
let position = dbInstance.getCenterForWay(id: way.id) ?? CLLocationCoordinate2D()
123123
let unit = DisplayUnitWithCoordinate(displayUnit: duplicateQuest.displayUnit, coordinateInfo: position, id: way.id, isHidden: false)
124124
displayUnits.append(unit)
125125
wayQuests.append(duplicateQuest)
@@ -171,7 +171,7 @@ class AppQuestManager {
171171

172172
}
173173
else if parserElement.type == .way {
174-
let position = dbInstance.getCenterForWay(id: String(parserElement.id)) ?? CLLocationCoordinate2D()
174+
let position = dbInstance.getCenterForWay(id: parserElement.id) ?? CLLocationCoordinate2D()
175175
let unit = DisplayUnitWithCoordinate(displayUnit: duplicateQuest.displayUnit, coordinateInfo: position, id: parserElement.id, isHidden: false)
176176
return unit
177177
}

GoInfoGame/GoInfoGame/DataBase/DBModels/StoredNode.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,20 @@ import osmapi
1414
// Stores a node instance
1515
class StoredNode : Object {
1616

17-
@Persisted(primaryKey: true) var compoundId: String
18-
@Persisted var id: Int
17+
@Persisted(primaryKey: true) var id: Int64
1918
@Persisted var tags = Map<String,String>()
2019
@Persisted var version: Int = 0
2120
@Persisted var timestamp : String = ""
2221
@Persisted var point: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
23-
24-
@Persisted var isOriginal: Bool = false
25-
26-
func generateCompoundId() {
27-
self.compoundId = "\(id)-\(isOriginal ? "original" : "edited")"
28-
}
29-
22+
3023
// Give another method that gives node
3124
public func asNode() -> Node {
3225
let position = LatLon(latitude: point.latitude , longitude: point.longitude)
3326
var theTags: [String:String] = [:]
3427
for (key,value) in tags{
3528
theTags[key] = value
3629
}
37-
let n = Node(id: Int64(id), version: version, tags: theTags, timestampEdited: 0, position: position)
30+
let n = Node(id: id, version: version, tags: theTags, timestampEdited: 0, position: position)
3831
return n
3932
}
4033
}

GoInfoGame/GoInfoGame/DataBase/DBModels/StoredWay.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,14 @@ import osmapi
1515
// Represents one stored way
1616
class StoredWay: Object {
1717

18-
@Persisted(primaryKey: true) var compoundId: String
19-
@Persisted var id: Int
18+
@Persisted(primaryKey: true) var id: Int64
2019
@Persisted var tags = Map<String,String>()
2120
@Persisted var version: Int = 0
2221
@Persisted var timestamp : String = ""
2322
@Persisted var nodes: List<Int64> = List<Int64>()
2423
// Need to persist the points
2524
@Persisted var polyline: List<CLLocationCoordinate2D> = List<CLLocationCoordinate2D>()
2625

27-
@Persisted var isOriginal: Bool = false
28-
29-
func generateCompoundId() {
30-
self.compoundId = "\(id)-\(isOriginal ? "original" : "edited")"
31-
}
32-
33-
3426
public func asWay() -> Way {
3527
var theTags: [String:String] = [:]
3628
for (key,value) in tags{

GoInfoGame/GoInfoGame/DataBase/DatabaseConnector.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DatabaseConnector {
5353
try realm.write {
5454
for node in nodes {
5555
let storedElement = StoredNode()
56-
storedElement.id = node.id
56+
storedElement.id = Int64(node.id)
5757
storedElement.tags.removeAll()
5858
node.tags.forEach { key, value in
5959
storedElement.tags[key] = value
@@ -62,7 +62,6 @@ class DatabaseConnector {
6262
let timestampString = dateFormatter.string(from: node.timestamp)
6363
storedElement.version = node.version
6464
storedElement.timestamp = timestampString
65-
storedElement.isOriginal = true
6665
// }
6766
if let asNode = node as? OSMNode{
6867
// coordinate from lat long
@@ -74,13 +73,12 @@ class DatabaseConnector {
7473
// continue
7574
// }
7675
}
77-
storedElement.generateCompoundId()
7876
realm.add(storedElement, update: .all)
7977
}
8078
// Store the ways
8179
for way in ways {
8280
let storedWay = StoredWay()
83-
storedWay.id = way.id
81+
storedWay.id = Int64(way.id)
8482
let timestampString = dateFormatter.string(from: way.timestamp)
8583
storedWay.tags.removeAll()
8684
way.tags.forEach { key, value in
@@ -90,7 +88,6 @@ class DatabaseConnector {
9088
}
9189
storedWay.version = way.version
9290
storedWay.timestamp = timestampString
93-
storedWay.isOriginal = true
9491
if let asWay = way as? OSMWay {
9592
storedWay.nodes.append(objectsIn: asWay.nodes.map({Int64($0)}))
9693
// Get all the points for the p
@@ -112,7 +109,6 @@ class DatabaseConnector {
112109
// print("Ignoring geometry")
113110
// }
114111
}
115-
storedWay.generateCompoundId()
116112
realm.add(storedWay, update: .all)
117113
}
118114
}
@@ -191,18 +187,16 @@ class DatabaseConnector {
191187
@param id String value of the way ID
192188
@returns CLLocationCoordinate2D the center location
193189
*/
194-
func getCenterForWay(id: String) -> CLLocationCoordinate2D? {
190+
func getCenterForWay(id: Int64) -> CLLocationCoordinate2D? {
195191
// Get all the objects for the way
196-
let compoundId = "\(id)-original" //
197-
guard let way = realm.object(ofType: StoredWay.self, forPrimaryKey: compoundId) else {
198-
return nil
199-
}
192+
guard let way = realm.object(ofType: StoredWay.self, forPrimaryKey: id) else {
193+
return nil
194+
}
200195
let nodeIds = way.nodes
201196
// Get the nodes for each
202197
var nodeCoords: [CLLocationCoordinate2D] = []
203198
for nodeId in nodeIds {
204-
let compoundNodeId = "\(nodeId)-original"
205-
if let node = realm.object(ofType: StoredNode.self , forPrimaryKey: compoundNodeId){
199+
if let node = realm.object(ofType: StoredNode.self , forPrimaryKey: nodeId){
206200
nodeCoords.append(node.point)
207201
}
208202
}
@@ -280,7 +274,7 @@ class DatabaseConnector {
280274
print("🟣 addNodeTags called for id: \(id) with tags: \(tags)")
281275

282276
if let editable = getNode(id: id) {
283-
print("✏️ Editable node exists: \(editable.compoundId)")
277+
print("✏️ Editable node exists: \(editable.id)")
284278
do {
285279
try realm.write {
286280
editable.tags.removeAll()

0 commit comments

Comments
 (0)