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.
main
sam marshall 2020-08-26 12:35:03 +01:00 committed by Dani Palou
parent eced391288
commit 069c402ba5
4 changed files with 25 additions and 5 deletions

View File

@ -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<number> {
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<number> {
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. * Returns the URL to the documentation of the app, based on Moodle version and current language.
* *

View File

@ -33,7 +33,6 @@
<ion-item text-wrap *ngIf="spaceUsage"> <ion-item text-wrap *ngIf="spaceUsage">
<h2 text-wrap>{{ 'core.settings.spaceusage' | translate }} <ion-icon name="information-circle" color="info" [attr.aria-label]="'core.info' | translate" (click)="showSpaceInfo()"></ion-icon></h2> <h2 text-wrap>{{ 'core.settings.spaceusage' | translate }} <ion-icon name="information-circle" color="info" [attr.aria-label]="'core.info' | translate" (click)="showSpaceInfo()"></ion-icon></h2>
<p *ngIf="spaceUsage.spaceUsage != null">{{ spaceUsage.spaceUsage | coreBytesToSize }}</p> <p *ngIf="spaceUsage.spaceUsage != null">{{ spaceUsage.spaceUsage | coreBytesToSize }}</p>
<p *ngIf="spaceUsage.cacheEntries != null">{{ 'core.settings.entriesincache' | translate: { $a: spaceUsage.cacheEntries } }}</p>
<button ion-button icon-only clear color="danger" item-end (click)="deleteSiteStorage()" [hidden]="!spaceUsage.spaceUsage > '0' && !spaceUsage.cacheEntries > '0'" [attr.aria-label]="'core.settings.deletesitefilestitle' | translate"> <button ion-button icon-only clear color="danger" item-end (click)="deleteSiteStorage()" [hidden]="!spaceUsage.spaceUsage > '0' && !spaceUsage.cacheEntries > '0'" [attr.aria-label]="'core.settings.deletesitefilestitle' | translate">
<ion-icon name="trash"></ion-icon> <ion-icon name="trash"></ion-icon>
</button> </button>

View File

@ -20,7 +20,6 @@
<p text-wrap>{{ site.fullName }}</p> <p text-wrap>{{ site.fullName }}</p>
<div item-end> <div item-end>
<p *ngIf="site.spaceUsage != null" text-end>{{ site.spaceUsage | coreBytesToSize }}</p> <p *ngIf="site.spaceUsage != null" text-end>{{ site.spaceUsage | coreBytesToSize }}</p>
<p *ngIf="site.cacheEntries != null" text-end>{{ 'core.settings.entriesincache' | translate: { $a: site.cacheEntries } }}</p>
</div> </div>
<button ion-button icon-only clear color="danger" item-end (click)="deleteSiteStorage(site)" [hidden]="!site.spaceUsage > '0' && !site.cacheEntries > '0'" [attr.aria-label]="'core.settings.deletesitefilestitle' | translate"> <button ion-button icon-only clear color="danger" item-end (click)="deleteSiteStorage(site)" [hidden]="!site.spaceUsage > '0' && !site.cacheEntries > '0'" [attr.aria-label]="'core.settings.deletesitefilestitle' | translate">
<ion-icon name="trash"></ion-icon> <ion-icon name="trash"></ion-icon>
@ -30,7 +29,6 @@
<h2>{{ 'core.settings.total' | translate }}</h2> <h2>{{ 'core.settings.total' | translate }}</h2>
<div item-end> <div item-end>
<p>{{ totals.spaceUsage | coreBytesToSize }}</p> <p>{{ totals.spaceUsage | coreBytesToSize }}</p>
<p>{{ 'core.settings.entriesincache' | translate: { $a: totals.cacheEntries } }}</p>
</div> </div>
</ion-item-divider> </ion-item-divider>
</core-loading> </core-loading>

View File

@ -34,7 +34,7 @@ import { TranslateService } from '@ngx-translate/core';
*/ */
export interface CoreSiteSpaceUsage { export interface CoreSiteSpaceUsage {
cacheEntries?: number; // Number of cached entries that can be cleared. cacheEntries?: number; // Number of cached entries that can be cleared.
spaceUsage?: number; // Space used in this site. spaceUsage?: number; // Space used in this site (total files + estimate of cache).
} }
/** /**
@ -154,7 +154,7 @@ export class CoreSettingsHelper {
await Promise.all([ await Promise.all([
this.calcSiteClearRows(site).then((rows) => siteInfo.cacheEntries = rows), this.calcSiteClearRows(site).then((rows) => siteInfo.cacheEntries = rows),
site.getSpaceUsage().then((size) => siteInfo.spaceUsage = size), site.getTotalUsage().then((size) => siteInfo.spaceUsage = size),
]); ]);
return siteInfo; return siteInfo;