Skip to content

Commit

Permalink
💄 feat: キャッシュサイズの表示を削除
Browse files Browse the repository at this point in the history
  • Loading branch information
reiroop committed Sep 24, 2024
1 parent 5eecf9c commit 26fd08b
Showing 1 changed file with 2 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
>
<div :class="$style.label">
{{ cacheLabel(name) }}
<span>{{ cacheSize[name] }}</span>
<!-- TODO: キャッシュサイズを表示する -->
</div>
</form-checkbox>
</div>
Expand All @@ -32,14 +32,13 @@
</template>

<script lang="ts" setup>
import { onMounted, ref, computed } from 'vue'
import { ref, computed } from 'vue'
import { useToastStore } from '/@/store/ui/toast'
import { wait } from '/@/lib/basic/timer'
import ModalFrame from '../Common/ModalFrame.vue'
import FormButton from '/@/components/UI/FormButton.vue'
import { useModalStore } from '/@/store/ui/modal'
import FormCheckbox from '/@/components/UI/FormCheckbox.vue'
import { prettifyFileSize } from '/@/lib/basic/file'
declare global {
interface StorageEstimate {
Expand Down Expand Up @@ -74,10 +73,6 @@ const anyCacheSelected = computed(() => {
return Object.values(cacheCategoryToIsSelected).includes(true)
})
const cacheSize = ref(
Object.fromEntries(cacheCategories.map(name => [name, '計算中...']))
)
const cacheNames = async (category: CacheCategory) => {
if (!(category === 'traQ_S-precache')) {
return [category]
Expand All @@ -86,42 +81,6 @@ const cacheNames = async (category: CacheCategory) => {
return allNames.filter(name => name.startsWith(category))
}
const updateCacheSize = async () => {
await Promise.all(
cacheCategories.map(async category => {
cacheSize.value[category] = prettifyFileSize(
await calculateCacheSizeSum(await cacheNames(category))
)
})
)
}
onMounted(updateCacheSize)
const calculateCacheSizeSum = async (cacheNames: string[]) => {
let size = 0
await Promise.all(
cacheNames.map(async cacheName => {
size += await calculateEachCacheSize(cacheName)
})
)
return size
}
const calculateEachCacheSize = async (cacheName: string) => {
const cache = await window.caches.open(cacheName)
const keys = await cache.keys()
let size = 0
await Promise.all(
keys.map(async key => {
const response = await cache.match(key)
if (!response) return
const blob = await response.blob()
size += blob.size
})
)
return size
}
const cacheLabel = (cacheCategory: CacheCategory) => {
switch (cacheCategory) {
case 'traQ_S-precache':
Expand Down

0 comments on commit 26fd08b

Please sign in to comment.