-
Notifications
You must be signed in to change notification settings - Fork 70
feat(cache): auto clear stale download cache on startup #1892
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -63,6 +63,12 @@ const DownloadSettingsPage = () => { | |
| const [speedLimitValue, setSpeedLimitValue] = useState<number>( | ||
| downloadConfigs.transmission.speedLimitValue | ||
| ); | ||
| const [retentionHours, setRetentionHours] = useState<number>( | ||
| downloadConfigs.cache.retentionHours | ||
| ); | ||
| const [sliderRetentionHours, setSliderRetentionHours] = useState<number>( | ||
| downloadConfigs.cache.retentionHours | ||
| ); | ||
| const [isClearingDownloadCache, setIsClearingDownloadCache] = | ||
| useState<boolean>(false); | ||
|
|
||
|
|
@@ -354,6 +360,79 @@ const DownloadSettingsPage = () => { | |
| </Button> | ||
| ), | ||
| }, | ||
| { | ||
| title: t("DownloadSettingPage.cache.settings.autoClear.title"), | ||
| description: t( | ||
| "DownloadSettingPage.cache.settings.autoClear.description" | ||
| ), | ||
| children: ( | ||
| <Switch | ||
| colorScheme={primaryColor} | ||
| isChecked={downloadConfigs.cache.autoClear} | ||
| onChange={(event) => { | ||
| update("download.cache.autoClear", event.target.checked); | ||
| }} | ||
| /> | ||
| ), | ||
| }, | ||
| ...(downloadConfigs.cache.autoClear | ||
| ? [ | ||
| { | ||
| title: t("DownloadSettingPage.cache.settings.retention.title"), | ||
| description: t( | ||
| "DownloadSettingPage.cache.settings.retention.description" | ||
| ), | ||
| children: ( | ||
| <HStack spacing={4}> | ||
| <Slider | ||
| min={1} | ||
| max={168} | ||
| step={1} | ||
| w={32} | ||
| colorScheme={primaryColor} | ||
| value={sliderRetentionHours} | ||
| onChange={(value) => { | ||
| setSliderRetentionHours(value); | ||
| setRetentionHours(value); | ||
|
Comment on lines
+387
to
+396
Contributor
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. suggestion (bug_risk): Keep slider value within min/max bounds when syncing from state
Suggested implementation: <Slider
min={1}
max={168}
step={1}
w={32}
colorScheme={primaryColor}
value={Math.min(168, Math.max(1, sliderRetentionHours))}
onChange={(value) => {
setSliderRetentionHours(value);
setRetentionHours(value);
}}
onBlur={() => {
const clampedRetentionHours = Math.min(
168,
Math.max(1, retentionHours)
);
update("download.cache.retentionHours", clampedRetentionHours);
}}To fully implement your comment, also ensure that any place where
setSliderRetentionHours(Math.min(168, Math.max(1, retentionHours)));This guarantees that both the state driving the slider and the value persisted via |
||
| }} | ||
| onBlur={() => { | ||
| update("download.cache.retentionHours", retentionHours); | ||
| }} | ||
| > | ||
| <SliderTrack> | ||
| <SliderFilledTrack /> | ||
| </SliderTrack> | ||
| <SliderThumb /> | ||
| </Slider> | ||
| <NumberInput | ||
| min={1} | ||
| max={168} | ||
| size="xs" | ||
| maxW={16} | ||
| focusBorderColor={`${primaryColor}.500`} | ||
| value={retentionHours} | ||
| onChange={(value) => { | ||
| if (!/^\d*$/.test(value)) return; | ||
| setRetentionHours(Number(value)); | ||
| }} | ||
| onBlur={() => { | ||
| setSliderRetentionHours(retentionHours); | ||
| update( | ||
| "download.cache.retentionHours", | ||
| Math.max(1, Math.min(retentionHours, 168)) | ||
| ); | ||
| }} | ||
| > | ||
| <NumberInputField /> | ||
| </NumberInput> | ||
| <Text fontSize="xs" className="secondary-text"> | ||
| h | ||
| </Text> | ||
| </HStack> | ||
| ), | ||
| }, | ||
| ] | ||
| : []), | ||
| ], | ||
| }, | ||
| { | ||
|
|
||
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.
suggestion (performance): Reuse metadata from
DirEntryto avoid extra syscallsWithin the loop,
tokio::fs::metadata(&path)is called for every entry even thoughDirEntrycan already provide metadata. For large caches this roughly doubles metadata syscalls. Preferentry.metadata().awaitand derive bothfile_typeandmodifiedfrom that single result to cut IO and simplify error handling.