Global: remove caching except image caching

This commit is contained in:
李通洲
2022-12-17 11:39:10 +08:00
parent 6a49ae60a1
commit ff6e982050
23 changed files with 133 additions and 565 deletions
+35 -35
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "common/printing.h"
#include "common/caching.h"
#include "detection/host/host.h"
#include "detection/gpu/gpu.h"
@@ -9,41 +8,47 @@
#define FF_GPU_MODULE_NAME "GPU"
#define FF_GPU_NUM_FORMAT_ARGS 5
static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* gpu)
static void printGPUResult(FFinstance* instance, uint8_t index, FFGPUResult* gpu)
{
FFstrbuf output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
if(instance->config.gpu.outputFormat.length == 0)
{
ffStrbufAppend(&output, &gpu->vendor);
ffStrbufAppendC(&output, ' ');
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu.key);
FFstrbuf output;
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
{
ffStrbufAppend(&output, &gpu->vendor);
ffStrbufAppendC(&output, ' ');
}
ffStrbufAppend(&output, &gpu->name);
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
ffStrbufPutTo(&output, stdout);
ffStrbufDestroy(&output);
}
else
{
ffPrintFormat(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature},
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
});
}
ffStrbufAppend(&output, &gpu->name);
if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET)
ffStrbufAppendF(&output, " (%d)", gpu->coreCount);
if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET
ffStrbufAppendF(&output, " - %.1f°C", gpu->temperature);
ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &output, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver},
{FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature}, //FIXME: temperature shouldn't be cached
{FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount},
});
ffStrbufDestroy(&output);
}
void ffPrintGPU(FFinstance* instance)
{
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS))
return;
const FFlist* gpus = ffDetectGPU(instance);
if(gpus->length == 0)
@@ -52,11 +57,6 @@ void ffPrintGPU(FFinstance* instance)
return;
}
FFcache cache;
ffCacheOpenWrite(instance, FF_GPU_MODULE_NAME, &cache);
for(uint8_t i = 0; i < (uint8_t) gpus->length; i++)
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), &cache, ffListGet(gpus, i));
ffCacheClose(&cache);
printGPUResult(instance, gpus->length == 1 ? 0 : (uint8_t) (i + 1), ffListGet(gpus, i));
}