mirror of
https://github.com/apple/pkl.git
synced 2026-03-26 02:51:13 +01:00
Introduce pkl-doc model version 2 (#1169)
Currently, in order to update a pkl-doc documentation site, almost the entire existing site is read in order to update metadata like known versions, known subtypes, and more. For example, adding a new version of a package requires that the existing runtime data of all existing versions be updated. Eventually, this causes the required storage size to balloon exponentially to the number of versions. This addresses these limitations by: 1. Updating the runtime data structure to move "known versions" metadata to the package level (the same JSON file is used for all versions). 2. Eliminating known subtype and known usage information at a cross-package level. 3. Generating the search index by consuming the previously generated search index. 4. Generating the main page by consuming the search index. Because this changes how runtime data is stored, an existing docsite needs to be migrated. This also introduces a new migration command, `pkl-doc --migrate`, which transforms an older version of the website into a newer version.
This commit is contained in:
33
pkl-commons/src/main/kotlin/org/pkl/commons/Control.kt
Normal file
33
pkl-commons/src/main/kotlin/org/pkl/commons/Control.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.commons
|
||||
|
||||
import java.util.WeakHashMap
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
// Adapted from https://stackoverflow.com/a/38084930
|
||||
fun <This, Return> lazyWithReceiver(
|
||||
initializer: This.() -> Return
|
||||
): LazyWithReceiver<This, Return> = LazyWithReceiver(initializer)
|
||||
|
||||
class LazyWithReceiver<This, out Return>(val initializer: This.() -> Return) {
|
||||
private val values = WeakHashMap<This, Return>()
|
||||
|
||||
private val lock = Object()
|
||||
|
||||
operator fun getValue(thisValue: This, property: KProperty<*>): Return =
|
||||
synchronized(lock) { values.getOrPut(thisValue) { thisValue.initializer() } }
|
||||
}
|
||||
Reference in New Issue
Block a user