From 069c402ba5f6f1009239b45113213544522b9eaf Mon Sep 17 00:00:00 2001 From: sam marshall Date: Wed, 26 Aug 2020 12:35:03 +0100 Subject: [PATCH] MOBILE-3188 Settings: Consistently show total size estimate for site Changes the two settings pages that show the size of a site (from the main menu, these are 'App settings / Space usage' and 'Preferences') so that they: a) do not show the number of cache entries (not very informative for end users) b) show an estimate for 'space usage' that includes the total size of data in ws_cache The space usage estimate is not perfect (it doesn't include the per-row overhead in the ws_cache table, or other cached data that can be deleted such as calendar events or user data) but it will probably be good enough, and I don't think the 'number of entries' things was helpful to anyone. --- src/classes/site.ts | 23 +++++++++++++++++++ src/core/settings/pages/site/site.html | 1 - .../pages/space-usage/space-usage.html | 2 -- src/core/settings/providers/helper.ts | 4 ++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/classes/site.ts b/src/classes/site.ts index 77f7e994f..8e8e4ffde 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -1384,6 +1384,29 @@ export class CoreSite { } } + /** + * Gets an approximation of the cache table usage of the site. + * + * Currently this is just the total length of the data fields in the cache table. + * + * @return Promise resolved with the total size of all data in the cache table (bytes) + */ + getCacheUsage(): Promise { + return this.db.getFieldSql('SELECT SUM(length(data)) FROM ' + CoreSite.WS_CACHE_TABLE); + } + + /** + * Gets a total of the file and cache usage. + * + * @return Promise with the total of getSpaceUsage and getCacheUsage + */ + async getTotalUsage(): Promise { + const space = await this.getSpaceUsage(); + const cache = await this.getCacheUsage(); + + return space + cache; + } + /** * Returns the URL to the documentation of the app, based on Moodle version and current language. * diff --git a/src/core/settings/pages/site/site.html b/src/core/settings/pages/site/site.html index 6c932d246..e03a107a1 100644 --- a/src/core/settings/pages/site/site.html +++ b/src/core/settings/pages/site/site.html @@ -33,7 +33,6 @@

{{ 'core.settings.spaceusage' | translate }}

{{ spaceUsage.spaceUsage | coreBytesToSize }}

-

{{ 'core.settings.entriesincache' | translate: { $a: spaceUsage.cacheEntries } }}

diff --git a/src/core/settings/pages/space-usage/space-usage.html b/src/core/settings/pages/space-usage/space-usage.html index 29dac4705..914cb1f9b 100644 --- a/src/core/settings/pages/space-usage/space-usage.html +++ b/src/core/settings/pages/space-usage/space-usage.html @@ -20,7 +20,6 @@

{{ site.fullName }}

{{ site.spaceUsage | coreBytesToSize }}

-

{{ 'core.settings.entriesincache' | translate: { $a: site.cacheEntries } }}