-
Couldn't load subscription status.
- Fork 11
fix: flaky watch on boot drive's dynamix config #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec7aa06
a9ea211
0a902b0
2f9265c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| {".":"4.25.2"} | ||
| {".":"4.25.3"} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| import { F_OK } from 'constants'; | ||
| import { access } from 'fs/promises'; | ||
|
|
||
| import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
| import { createTtlMemoizedLoader } from '@unraid/shared'; | ||
|
|
||
| import type { RecursivePartial } from '@app/types/index.js'; | ||
| import { type DynamixConfig } from '@app/core/types/ini.js'; | ||
| import { fileExistsSync } from '@app/core/utils/files/file-exists.js'; | ||
| import { parseConfig } from '@app/core/utils/misc/parse-config.js'; | ||
| import { type RecursiveNullable, type RecursivePartial } from '@app/types/index.js'; | ||
| import { batchProcess } from '@app/utils.js'; | ||
|
|
||
| /** | ||
| * Loads a configuration file from disk, parses it to a RecursivePartial of the provided type, and returns it. | ||
|
|
@@ -16,33 +13,49 @@ import { batchProcess } from '@app/utils.js'; | |
| * @param path The path to the configuration file on disk. | ||
| * @returns A parsed RecursivePartial of the provided type. | ||
| */ | ||
| async function loadConfigFile<ConfigType>(path: string): Promise<RecursivePartial<ConfigType>> { | ||
| const fileIsAccessible = await access(path, F_OK) | ||
| .then(() => true) | ||
| .catch(() => false); | ||
| return fileIsAccessible | ||
| function loadConfigFileSync<ConfigType>(path: string): RecursivePartial<ConfigType> { | ||
| return fileExistsSync(path) | ||
| ? parseConfig<RecursivePartial<ConfigType>>({ | ||
| filePath: path, | ||
| type: 'ini', | ||
| }) | ||
| : {}; | ||
| } | ||
|
|
||
| type ConfigPaths = readonly (string | undefined | null)[]; | ||
| const CACHE_WINDOW_MS = 250; | ||
|
|
||
| const memoizedConfigLoader = createTtlMemoizedLoader< | ||
| RecursivePartial<DynamixConfig>, | ||
| ConfigPaths, | ||
| string | ||
| >({ | ||
| ttlMs: CACHE_WINDOW_MS, | ||
| getCacheKey: (configPaths: ConfigPaths): string => JSON.stringify(configPaths), | ||
| load: (configPaths: ConfigPaths) => { | ||
| const validPaths = configPaths.filter((path): path is string => Boolean(path)); | ||
| if (validPaths.length === 0) { | ||
| return {}; | ||
| } | ||
| const configFiles = validPaths.map((path) => loadConfigFileSync<DynamixConfig>(path)); | ||
| return configFiles.reduce<RecursivePartial<DynamixConfig>>( | ||
| (accumulator, configFile) => ({ | ||
| ...accumulator, | ||
| ...configFile, | ||
| }), | ||
| {} | ||
| ); | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * Load the dynamix.cfg into the store. | ||
| * Loads dynamix config from disk with TTL caching. | ||
| * | ||
| * Note: If the file doesn't exist this will fallback to default values. | ||
| * @param configPaths - Array of config file paths to load and merge | ||
| * @returns Merged config object from all valid paths | ||
| */ | ||
| export const loadDynamixConfigFile = createAsyncThunk< | ||
| RecursiveNullable<RecursivePartial<DynamixConfig>>, | ||
| string | undefined | ||
| >('config/load-dynamix-config-file', async (filePath) => { | ||
| if (filePath) { | ||
| return loadConfigFile<DynamixConfig>(filePath); | ||
| } | ||
| const store = await import('@app/store/index.js'); | ||
| const paths = store.getters.paths()['dynamix-config']; | ||
| const { data: configs } = await batchProcess(paths, (path) => loadConfigFile<DynamixConfig>(path)); | ||
| const [defaultConfig = {}, customConfig = {}] = configs; | ||
| return { ...defaultConfig, ...customConfig }; | ||
| }); | ||
| export const loadDynamixConfigFromDiskSync = ( | ||
| configPaths: readonly (string | undefined | null)[] | ||
| ): RecursivePartial<DynamixConfig> => { | ||
| return memoizedConfigLoader.get(configPaths); | ||
|
Comment on lines
+25
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new memoized loader keeps a 250 ms snapshot of the config ( Useful? React with 👍 / 👎. |
||
| }; | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the compare URL repository path
The new 4.25.3 entry points to
https://github.com/unraid/unraid-api/compare/..., but the rest of this changelog—and the actual repo—usehttps://github.com/unraid/api/compare/.... That typo breaks the compare link for this release. Please change the URL tohttps://github.com/unraid/api/compare/v4.25.2...v4.25.3to keep the changelog consistent and the link working.🤖 Prompt for AI Agents