2023-01-16 17:40:28 -08:00
|
|
|
//
|
|
|
|
|
// QueryCoreData.swift
|
|
|
|
|
// Meshtastic
|
|
|
|
|
//
|
|
|
|
|
// Created(c) Garth Vander Houwen 1/16/23.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import CoreData
|
|
|
|
|
|
2023-02-06 18:45:03 -08:00
|
|
|
public func getNodeInfo(id: Int64, context: NSManagedObjectContext) -> NodeInfoEntity? {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchNodeInfoRequest = NodeInfoEntity.fetchRequest()
|
2023-01-31 10:50:17 -08:00
|
|
|
fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(id))
|
perf: Quick-win performance optimizations for node list and Core Data lookups (#1650)
* feat: improve routing performance with split state, fetch batching, node cache, and debounce
- Split Router's single @Published navigationState into per-tab properties
to reduce spurious re-renders across unrelated views
- Add fetchBatchSize=50 and relationshipKeyPathsForPrefetching to node list
- Optimize in-body array re-sort from 2 filter passes to single pass
- Add in-memory node object ID cache on Router for O(1) lookups
- Add fetchLimit=1 to getNodeInfo for early termination
- Debounce rapid node selection changes with 100ms Task delay
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/9bfe91f2-8ed7-4d2c-bb2e-4ed3dfd3a16c
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Address code review: add debounce constant and thread-safety comment
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/9bfe91f2-8ed7-4d2c-bb2e-4ed3dfd3a16c
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Migrate test project to Swift Testing and add connect view and router tests (#1643)
* Migrate to Swift Testing and add connect view tests
- Convert RouterTests.swift from XCTest to Swift Testing (@Suite, @Test, #expect, #require)
- Create ConnectViewTests.swift with tests for connect view child types:
- Device struct (creation, signal strength, RSSI, description, codable)
- TransportType enum (cases, raw values, codable)
- ConnectionState enum (equality, codable)
- BLESignalStrength enum (raw values, init)
- TransportStatus enum (equality)
- NavigationState (defaults, tabs, sub-states)
- InvalidVersion view (creation with versions)
- ConnectedDevice view (connected/disconnected/MQTT states)
- CircleText view (default/custom sizes, emoji)
- BatteryCompact view (levels, nil, charging, plugged in)
- SignalStrengthIndicator view (dimensions, strength levels)
- Update Xcode project to include new test file
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/d7bb7a89-2105-4fcb-96bc-7ec794467c74
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Fix signal strength test boundary conditions
The getSignalStrength() method uses NSNumber.compare(.orderedDescending),
which is a strict greater-than check. Fix the boundary test cases:
- RSSI -65 is .normal (not .strong), since -65 is not > -65
- RSSI -85 is .weak (not .normal), since -85 is not > -85
- Add -64 → .strong and -84 → .normal as adjacent boundary tests
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/4fcbc01e-cbea-4d11-b2c0-e923c6730d69
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Improve and complete router tests with comprehensive coverage
Added tests for:
- Custom initial state
- Invalid scheme / unknown path handling (state unchanged)
- navigateToNodeDetail public method
- Messages edge cases: channelId only, userNum only, messageId only, non-numeric params
- Nodes with non-numeric nodenum
- Map with both nodenum+waypointId (nodeId priority), non-numeric params
- Parameterized settings test covering all 31 SettingsNavigationState cases
- State transitions: consecutive routes, invalid scheme preserves existing state
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/f69b7352-21aa-494c-8864-31fc0f4b21b8
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Localizable update
* Merge translations file
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
* Fix merge conflicts in PR #1614 (Spanish translations) (#1644)
* 20% of strings translated to spanish
* add more translations
* add rest of translations
* small fixes
---------
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* fix typo in hop limit option description (#1631)
O hop -> 0 hop
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Tak server improvements (#1603)
* added read only mode cot to meshtastic parsing and warning to not enable on pub channel
* better icons
* fully fixed markers
* telemetry support
* Update Meshtastic/Helpers/TAK/TAKServerManager.swift
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* fixes
* fixes
* Resolve merge conflicts for PR #1603 (TAK server improvements) (#1645)
* Delete Messages fix
* Bump version to 2.7.9
* Bump widgets version
* TAK Server channel index picker
Create a settings picker for the TAK Server's channel index. This allows users to specify TAK traffic to use the non-primary channel to help reduce channel congestion.
* Changed capitalization from 'environment' to 'Environment' for section header. (#1591)
* Add Danish (da) translations — resolves merge conflicts from PR #1609 (#1612)
* Initial plan
* Add Danish (da) translations from PR #1609
Resolves merge conflicts from PR #1609 by adding Danish translations to the
Localizable.xcstrings file. The PR adds Danish translation strings throughout
the app while preserving all existing translations for other languages.
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Migrate test project to Swift Testing and add connect view and router tests (#1643)
* Migrate to Swift Testing and add connect view tests
- Convert RouterTests.swift from XCTest to Swift Testing (@Suite, @Test, #expect, #require)
- Create ConnectViewTests.swift with tests for connect view child types:
- Device struct (creation, signal strength, RSSI, description, codable)
- TransportType enum (cases, raw values, codable)
- ConnectionState enum (equality, codable)
- BLESignalStrength enum (raw values, init)
- TransportStatus enum (equality)
- NavigationState (defaults, tabs, sub-states)
- InvalidVersion view (creation with versions)
- ConnectedDevice view (connected/disconnected/MQTT states)
- CircleText view (default/custom sizes, emoji)
- BatteryCompact view (levels, nil, charging, plugged in)
- SignalStrengthIndicator view (dimensions, strength levels)
- Update Xcode project to include new test file
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/d7bb7a89-2105-4fcb-96bc-7ec794467c74
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Fix signal strength test boundary conditions
The getSignalStrength() method uses NSNumber.compare(.orderedDescending),
which is a strict greater-than check. Fix the boundary test cases:
- RSSI -65 is .normal (not .strong), since -65 is not > -65
- RSSI -85 is .weak (not .normal), since -85 is not > -85
- Add -64 → .strong and -84 → .normal as adjacent boundary tests
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/4fcbc01e-cbea-4d11-b2c0-e923c6730d69
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Improve and complete router tests with comprehensive coverage
Added tests for:
- Custom initial state
- Invalid scheme / unknown path handling (state unchanged)
- navigateToNodeDetail public method
- Messages edge cases: channelId only, userNum only, messageId only, non-numeric params
- Nodes with non-numeric nodenum
- Map with both nodenum+waypointId (nodeId priority), non-numeric params
- Parameterized settings test covering all 31 SettingsNavigationState cases
- State transitions: consecutive routes, invalid scheme preserves existing state
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/f69b7352-21aa-494c-8864-31fc0f4b21b8
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Localizable update
* Merge translations file
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
* Fix merge conflicts in PR #1614 (Spanish translations) (#1644)
* 20% of strings translated to spanish
* add more translations
* add rest of translations
* small fixes
---------
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* fix typo in hop limit option description (#1631)
O hop -> 0 hop
---------
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: niccellular <79813408+niccellular@users.noreply.github.com>
Co-authored-by: Austin Hargis <25471876+austinhargis@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: axunes <axunes@axunes.net>
* Fix merge conflicts
* Merge main into tak-server-improvements to resolve PR #1603 conflicts (#1646)
* Delete Messages fix
* Bump version to 2.7.9
* Bump widgets version
* TAK Server channel index picker
Create a settings picker for the TAK Server's channel index. This allows users to specify TAK traffic to use the non-primary channel to help reduce channel congestion.
* Changed capitalization from 'environment' to 'Environment' for section header. (#1591)
* Add Danish (da) translations — resolves merge conflicts from PR #1609 (#1612)
* Initial plan
* Add Danish (da) translations from PR #1609
Resolves merge conflicts from PR #1609 by adding Danish translations to the
Localizable.xcstrings file. The PR adds Danish translation strings throughout
the app while preserving all existing translations for other languages.
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Migrate test project to Swift Testing and add connect view and router tests (#1643)
* Migrate to Swift Testing and add connect view tests
- Convert RouterTests.swift from XCTest to Swift Testing (@Suite, @Test, #expect, #require)
- Create ConnectViewTests.swift with tests for connect view child types:
- Device struct (creation, signal strength, RSSI, description, codable)
- TransportType enum (cases, raw values, codable)
- ConnectionState enum (equality, codable)
- BLESignalStrength enum (raw values, init)
- TransportStatus enum (equality)
- NavigationState (defaults, tabs, sub-states)
- InvalidVersion view (creation with versions)
- ConnectedDevice view (connected/disconnected/MQTT states)
- CircleText view (default/custom sizes, emoji)
- BatteryCompact view (levels, nil, charging, plugged in)
- SignalStrengthIndicator view (dimensions, strength levels)
- Update Xcode project to include new test file
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/d7bb7a89-2105-4fcb-96bc-7ec794467c74
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Fix signal strength test boundary conditions
The getSignalStrength() method uses NSNumber.compare(.orderedDescending),
which is a strict greater-than check. Fix the boundary test cases:
- RSSI -65 is .normal (not .strong), since -65 is not > -65
- RSSI -85 is .weak (not .normal), since -85 is not > -85
- Add -64 → .strong and -84 → .normal as adjacent boundary tests
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/4fcbc01e-cbea-4d11-b2c0-e923c6730d69
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Improve and complete router tests with comprehensive coverage
Added tests for:
- Custom initial state
- Invalid scheme / unknown path handling (state unchanged)
- navigateToNodeDetail public method
- Messages edge cases: channelId only, userNum only, messageId only, non-numeric params
- Nodes with non-numeric nodenum
- Map with both nodenum+waypointId (nodeId priority), non-numeric params
- Parameterized settings test covering all 31 SettingsNavigationState cases
- State transitions: consecutive routes, invalid scheme preserves existing state
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/f69b7352-21aa-494c-8864-31fc0f4b21b8
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Localizable update
* Merge translations file
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
* Fix merge conflicts in PR #1614 (Spanish translations) (#1644)
* 20% of strings translated to spanish
* add more translations
* add rest of translations
* small fixes
---------
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* fix typo in hop limit option description (#1631)
O hop -> 0 hop
---------
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: niccellular <79813408+niccellular@users.noreply.github.com>
Co-authored-by: Austin Hargis <25471876+austinhargis@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: axunes <axunes@axunes.net>
* Merge main into tak-server-improvements to resolve PR #1603 conflicts (#1647)
* Delete Messages fix
* Bump version to 2.7.9
* Bump widgets version
* TAK Server channel index picker
Create a settings picker for the TAK Server's channel index. This allows users to specify TAK traffic to use the non-primary channel to help reduce channel congestion.
* Changed capitalization from 'environment' to 'Environment' for section header. (#1591)
* Add Danish (da) translations — resolves merge conflicts from PR #1609 (#1612)
* Initial plan
* Add Danish (da) translations from PR #1609
Resolves merge conflicts from PR #1609 by adding Danish translations to the
Localizable.xcstrings file. The PR adds Danish translation strings throughout
the app while preserving all existing translations for other languages.
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Migrate test project to Swift Testing and add connect view and router tests (#1643)
* Migrate to Swift Testing and add connect view tests
- Convert RouterTests.swift from XCTest to Swift Testing (@Suite, @Test, #expect, #require)
- Create ConnectViewTests.swift with tests for connect view child types:
- Device struct (creation, signal strength, RSSI, description, codable)
- TransportType enum (cases, raw values, codable)
- ConnectionState enum (equality, codable)
- BLESignalStrength enum (raw values, init)
- TransportStatus enum (equality)
- NavigationState (defaults, tabs, sub-states)
- InvalidVersion view (creation with versions)
- ConnectedDevice view (connected/disconnected/MQTT states)
- CircleText view (default/custom sizes, emoji)
- BatteryCompact view (levels, nil, charging, plugged in)
- SignalStrengthIndicator view (dimensions, strength levels)
- Update Xcode project to include new test file
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/d7bb7a89-2105-4fcb-96bc-7ec794467c74
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Fix signal strength test boundary conditions
The getSignalStrength() method uses NSNumber.compare(.orderedDescending),
which is a strict greater-than check. Fix the boundary test cases:
- RSSI -65 is .normal (not .strong), since -65 is not > -65
- RSSI -85 is .weak (not .normal), since -85 is not > -85
- Add -64 → .strong and -84 → .normal as adjacent boundary tests
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/4fcbc01e-cbea-4d11-b2c0-e923c6730d69
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Improve and complete router tests with comprehensive coverage
Added tests for:
- Custom initial state
- Invalid scheme / unknown path handling (state unchanged)
- navigateToNodeDetail public method
- Messages edge cases: channelId only, userNum only, messageId only, non-numeric params
- Nodes with non-numeric nodenum
- Map with both nodenum+waypointId (nodeId priority), non-numeric params
- Parameterized settings test covering all 31 SettingsNavigationState cases
- State transitions: consecutive routes, invalid scheme preserves existing state
Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/f69b7352-21aa-494c-8864-31fc0f4b21b8
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* Localizable update
* Merge translations file
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
* Fix merge conflicts in PR #1614 (Spanish translations) (#1644)
* 20% of strings translated to spanish
* add more translations
* add rest of translations
* small fixes
---------
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
* fix typo in hop limit option description (#1631)
O hop -> 0 hop
---------
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: niccellular <79813408+niccellular@users.noreply.github.com>
Co-authored-by: Austin Hargis <25471876+austinhargis@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: axunes <axunes@axunes.net>
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: niccellular <79813408+niccellular@users.noreply.github.com>
Co-authored-by: Austin Hargis <25471876+austinhargis@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: axunes <axunes@axunes.net>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: Joel Pérez Izquierdo <joelperez91@gmail.com>
Co-authored-by: axunes <axunes@axunes.net>
Co-authored-by: Benjamin Faershtein <119711889+RCGV1@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jake-B <jake-b@users.noreply.github.com>
Co-authored-by: niccellular <79813408+niccellular@users.noreply.github.com>
Co-authored-by: Austin Hargis <25471876+austinhargis@users.noreply.github.com>
Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2026-04-04 18:51:00 -07:00
|
|
|
fetchNodeInfoRequest.fetchLimit = 1
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-01-31 10:50:17 -08:00
|
|
|
do {
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchedNode = try context.fetch(fetchNodeInfoRequest)
|
2023-03-06 15:30:10 -08:00
|
|
|
if fetchedNode.count == 1 {
|
|
|
|
|
return fetchedNode[0]
|
2023-01-31 10:50:17 -08:00
|
|
|
}
|
|
|
|
|
} catch {
|
2023-02-06 18:45:03 -08:00
|
|
|
return nil
|
2023-01-31 10:50:17 -08:00
|
|
|
}
|
2023-02-06 18:45:03 -08:00
|
|
|
return nil
|
2023-01-31 10:50:17 -08:00
|
|
|
}
|
|
|
|
|
|
2023-10-01 12:25:38 -07:00
|
|
|
public func getStoreAndForwardMessageIds(seconds: Int, context: NSManagedObjectContext) -> [UInt32] {
|
2024-05-29 16:40:07 -05:00
|
|
|
|
2023-10-01 12:25:38 -07:00
|
|
|
let time = seconds * -1
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchMessagesRequest = MessageEntity.fetchRequest()
|
2023-10-01 12:25:38 -07:00
|
|
|
let timeRange = Calendar.current.date(byAdding: .minute, value: time, to: Date())
|
|
|
|
|
let milleseconds = Int32(timeRange?.timeIntervalSince1970 ?? 0)
|
2024-07-31 20:56:09 -07:00
|
|
|
fetchMessagesRequest.predicate = NSPredicate(format: "messageTimestamp >= %d", milleseconds)
|
2023-10-01 12:25:38 -07:00
|
|
|
|
|
|
|
|
do {
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchedMessages = try context.fetch(fetchMessagesRequest)
|
2023-10-01 12:25:38 -07:00
|
|
|
if fetchedMessages.count == 1 {
|
|
|
|
|
return fetchedMessages.map { UInt32($0.messageId) }
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 11:41:29 -08:00
|
|
|
public func getTraceRoute(id: Int64, context: NSManagedObjectContext) -> TraceRouteEntity? {
|
|
|
|
|
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchTraceRouteRequest = TraceRouteEntity.fetchRequest()
|
2023-12-08 11:41:29 -08:00
|
|
|
fetchTraceRouteRequest.predicate = NSPredicate(format: "id == %lld", Int64(id))
|
|
|
|
|
|
|
|
|
|
do {
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchedTraceRoute = try context.fetch(fetchTraceRouteRequest)
|
2023-12-08 11:41:29 -08:00
|
|
|
if fetchedTraceRoute.count == 1 {
|
|
|
|
|
return fetchedTraceRoute[0]
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2023-10-01 12:25:38 -07:00
|
|
|
|
2023-01-31 10:50:17 -08:00
|
|
|
public func getUser(id: Int64, context: NSManagedObjectContext) -> UserEntity {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchUserRequest = UserEntity.fetchRequest()
|
2023-01-31 10:50:17 -08:00
|
|
|
fetchUserRequest.predicate = NSPredicate(format: "num == %lld", Int64(id))
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-01-31 10:50:17 -08:00
|
|
|
do {
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchedUser = try context.fetch(fetchUserRequest)
|
2023-01-31 10:50:17 -08:00
|
|
|
if fetchedUser.count == 1 {
|
|
|
|
|
return fetchedUser[0]
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
return UserEntity(context: context)
|
|
|
|
|
}
|
|
|
|
|
return UserEntity(context: context)
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 17:40:28 -08:00
|
|
|
public func getWaypoint(id: Int64, context: NSManagedObjectContext) -> WaypointEntity {
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchWaypointRequest = WaypointEntity.fetchRequest()
|
2023-01-16 17:40:28 -08:00
|
|
|
fetchWaypointRequest.predicate = NSPredicate(format: "id == %lld", Int64(id))
|
2023-03-06 10:33:18 -08:00
|
|
|
|
2023-01-16 17:40:28 -08:00
|
|
|
do {
|
2024-06-28 08:50:49 -05:00
|
|
|
let fetchedWaypoint = try context.fetch(fetchWaypointRequest)
|
2023-01-16 17:40:28 -08:00
|
|
|
if fetchedWaypoint.count == 1 {
|
|
|
|
|
return fetchedWaypoint[0]
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
2023-01-16 23:16:57 -08:00
|
|
|
return WaypointEntity(context: context)
|
2023-01-16 17:40:28 -08:00
|
|
|
}
|
2023-01-16 23:16:57 -08:00
|
|
|
return WaypointEntity(context: context)
|
2023-01-16 17:40:28 -08:00
|
|
|
}
|