Skip to content

Commit

Permalink
Remove CustomRasterSourec/tileCacheBudget (#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
maios authored Jun 20, 2024
1 parent e53b2e5 commit e5cf9a5
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 28 deletions.
20 changes: 1 addition & 19 deletions Sources/MapboxMaps/Style/CustomSources/CustomRasterSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public struct CustomRasterSource: Source, Equatable {
@_documentation(visibility: public)
public let options: CustomRasterSourceOptions?

/// This property defines a source-specific resource budget, either in tile units or in megabytes. Whenever the tile cache goes over the defined limit, the least recently used tile will be evicted from the in-memory cache. Note that the current implementation does not take into account resources allocated by the visible tiles.
@_documentation(visibility: public)
public var tileCacheBudget: TileCacheBudgetSize?

@_documentation(visibility: public)
public init(id: String, options: CustomRasterSourceOptions) {
self.id = id
Expand All @@ -34,33 +30,19 @@ extension CustomRasterSource {
enum CodingKeys: String, CodingKey {
case id
case type
case tileCacheBudget = "tile-cache-budget"
}

/// Init from a decoder, note that the CustomRasterSourceOptions are not decodable and need to be set separately
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
tileCacheBudget = try container.decodeIfPresent(TileCacheBudgetSize.self, forKey: .tileCacheBudget)
options = nil
}

/// Encode, note that options will not be included
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

if encoder.userInfo[.volatilePropertiesOnly] as? Bool == true {
try encodeVolatile(to: encoder, into: &container)
} else if encoder.userInfo[.nonVolatilePropertiesOnly] as? Bool == true {
try encodeNonVolatile(to: encoder, into: &container)
} else {
try encodeVolatile(to: encoder, into: &container)
try encodeNonVolatile(to: encoder, into: &container)
}
}

private func encodeVolatile(to encoder: Encoder, into container: inout KeyedEncodingContainer<CodingKeys>) throws {
try container.encodeIfPresent(tileCacheBudget, forKey: .tileCacheBudget)
try encodeNonVolatile(to: encoder, into: &container)
}

private func encodeNonVolatile(to encoder: Encoder, into container: inout KeyedEncodingContainer<CodingKeys>) throws {
Expand Down
5 changes: 0 additions & 5 deletions Sources/MapboxMaps/Style/Generated/SourceWrapper.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ final class CustomSourcesIntegrationTests: MapViewIntegrationTestCase {

didFinishLoadingStyle = { mapView in
var source = CustomRasterSource(id: "test-source", options: CustomRasterSourceOptions(tileStatusChangedFunction: { _, _ in }))
source.tileCacheBudget = .testSourceValue(.megabytes(7))

// Add source
do {
Expand All @@ -27,7 +26,6 @@ final class CustomSourcesIntegrationTests: MapViewIntegrationTestCase {
// Retrieve the source
do {
let retrievedSource = try mapView.mapboxMap.source(withId: "test-source", type: CustomRasterSource.self)
XCTAssertEqual(retrievedSource.tileCacheBudget, .testSourceValue(.megabytes(7)))

successfullyRetrievedSourceExpectation.fulfill()
} catch {
Expand Down
2 changes: 0 additions & 2 deletions Tests/MapboxMapsTests/Style/CustomSourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ final class CustomSourcesSourceTests: XCTestCase {
let testCustomRasterSourceOptions = CustomRasterSourceOptions(tileStatusChangedFunction: { _, _ in })

var source = CustomRasterSource(id: "test-source", options: testCustomRasterSourceOptions)
source.tileCacheBudget = TileCacheBudgetSize.testSourceValue(TileCacheBudgetSize.megabytes(7))

var data: Data?
do {
Expand All @@ -25,7 +24,6 @@ final class CustomSourcesSourceTests: XCTestCase {
let decodedSource = try JSONDecoder().decode(CustomRasterSource.self, from: validData)
XCTAssert(decodedSource.type == SourceType.customRaster)
XCTAssert(decodedSource.id == "test-source")
XCTAssert(decodedSource.tileCacheBudget == TileCacheBudgetSize.testSourceValue(TileCacheBudgetSize.megabytes(7)))
XCTAssertNil(decodedSource.options)
} catch {
XCTFail("Failed to decode CustomRasterSource.")
Expand Down
1 change: 1 addition & 0 deletions scripts/api-compatibility-check/breakage_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1437,3 +1437,4 @@ Func StyleManager.invalidateCustomRasterSourceRegion(forSourceId:bounds:) has be
Func StyleManager.invalidateCustomRasterSourceTile(forSourceId:tileId:) has been removed
Func StyleManager.setCustomRasterSourceTileData(forSourceId:tileId:image:) has been renamed to Func setCustomRasterSourceTileData(forSourceId:tiles:)
Func StyleManager.setCustomRasterSourceTileData(forSourceId:tileId:image:) has parameter 1 type change from MapboxCoreMaps.CanonicalTileID to [MapboxCoreMaps.CustomRasterSourceTileData]
Var CustomRasterSource.tileCacheBudget has been removed

0 comments on commit e5cf9a5

Please sign in to comment.