MOBILE-2848 eslint: Fix warnings in Site, Lang, WS
parent
d7e6e04f65
commit
9efe5a5c09
|
@ -309,10 +309,7 @@ export class CoreSite {
|
||||||
|
|
||||||
// Index function by name to speed up wsAvailable method.
|
// Index function by name to speed up wsAvailable method.
|
||||||
if (infos?.functions) {
|
if (infos?.functions) {
|
||||||
infos.functionsByName = {};
|
infos.functionsByName = CoreUtils.arrayToObject(infos.functions, 'name');
|
||||||
infos.functions.forEach((func) => {
|
|
||||||
infos.functionsByName![func.name] = func;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -907,7 +904,8 @@ export class CoreSite {
|
||||||
preSets: CoreSiteWSPreSets,
|
preSets: CoreSiteWSPreSets,
|
||||||
emergency?: boolean,
|
emergency?: boolean,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
if (!this.db || !preSets.getFromCache) {
|
const db = this.db;
|
||||||
|
if (!db || !preSets.getFromCache) {
|
||||||
throw new CoreError('Get from cache is disabled.');
|
throw new CoreError('Get from cache is disabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -915,11 +913,11 @@ export class CoreSite {
|
||||||
let entry: CoreSiteWSCacheRecord | undefined;
|
let entry: CoreSiteWSCacheRecord | undefined;
|
||||||
|
|
||||||
if (preSets.getCacheUsingCacheKey || (emergency && preSets.getEmergencyCacheUsingCacheKey)) {
|
if (preSets.getCacheUsingCacheKey || (emergency && preSets.getEmergencyCacheUsingCacheKey)) {
|
||||||
const entries = await this.db.getRecords<CoreSiteWSCacheRecord>(CoreSite.WS_CACHE_TABLE, { key: preSets.cacheKey });
|
const entries = await db.getRecords<CoreSiteWSCacheRecord>(CoreSite.WS_CACHE_TABLE, { key: preSets.cacheKey });
|
||||||
|
|
||||||
if (!entries.length) {
|
if (!entries.length) {
|
||||||
// Cache key not found, get by params sent.
|
// Cache key not found, get by params sent.
|
||||||
entry = await this.db!.getRecord(CoreSite.WS_CACHE_TABLE, { id });
|
entry = await db.getRecord(CoreSite.WS_CACHE_TABLE, { id });
|
||||||
} else {
|
} else {
|
||||||
if (entries.length > 1) {
|
if (entries.length > 1) {
|
||||||
// More than one entry found. Search the one with same ID as this call.
|
// More than one entry found. Search the one with same ID as this call.
|
||||||
|
@ -931,7 +929,7 @@ export class CoreSite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
entry = await this.db!.getRecord(CoreSite.WS_CACHE_TABLE, { id });
|
entry = await db.getRecord(CoreSite.WS_CACHE_TABLE, { id });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof entry == 'undefined') {
|
if (typeof entry == 'undefined') {
|
||||||
|
@ -946,7 +944,7 @@ export class CoreSite {
|
||||||
if (!preSets.omitExpires) {
|
if (!preSets.omitExpires) {
|
||||||
expirationTime = entry.expirationTime + this.getExpirationDelay(preSets.updateFrequency);
|
expirationTime = entry.expirationTime + this.getExpirationDelay(preSets.updateFrequency);
|
||||||
|
|
||||||
if (now > expirationTime!) {
|
if (now > expirationTime) {
|
||||||
this.logger.debug('Cached element found, but it is expired');
|
this.logger.debug('Cached element found, but it is expired');
|
||||||
|
|
||||||
throw new CoreError('Cache entry is expired.');
|
throw new CoreError('Cache entry is expired.');
|
||||||
|
@ -1747,7 +1745,12 @@ export class CoreSite {
|
||||||
|
|
||||||
if (CoreSite.MOODLE_RELEASES[data.major] === undefined) {
|
if (CoreSite.MOODLE_RELEASES[data.major] === undefined) {
|
||||||
// Major version not found. Use the last one.
|
// Major version not found. Use the last one.
|
||||||
data.major = Object.keys(CoreSite.MOODLE_RELEASES).pop()!;
|
const major = Object.keys(CoreSite.MOODLE_RELEASES).pop();
|
||||||
|
if (!major) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.major = major;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CoreSite.MOODLE_RELEASES[data.major] + data.minor;
|
return CoreSite.MOODLE_RELEASES[data.major] + data.minor;
|
||||||
|
|
|
@ -403,11 +403,11 @@ export class CoreLangProvider {
|
||||||
|
|
||||||
this.customStringsRaw = strings;
|
this.customStringsRaw = strings;
|
||||||
|
|
||||||
if (currentLangChanged) {
|
if (currentLangChanged && this.currentLanguage) {
|
||||||
// Some lang strings have changed, emit an event to update the pipes.
|
// Some lang strings have changed, emit an event to update the pipes.
|
||||||
Translate.onLangChange.emit({
|
Translate.onLangChange.emit({
|
||||||
lang: this.currentLanguage!,
|
lang: this.currentLanguage,
|
||||||
translations: Translate.translations[this.currentLanguage!],
|
translations: Translate.translations[this.currentLanguage],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,8 +336,9 @@ export class CoreWSProvider {
|
||||||
* @return Promise resolved with the mimetype or '' if failure.
|
* @return Promise resolved with the mimetype or '' if failure.
|
||||||
*/
|
*/
|
||||||
async getRemoteFileMimeType(url: string, ignoreCache?: boolean): Promise<string> {
|
async getRemoteFileMimeType(url: string, ignoreCache?: boolean): Promise<string> {
|
||||||
if (this.mimeTypeCache[url] && !ignoreCache) {
|
const cachedMimeType = this.mimeTypeCache[url];
|
||||||
return this.mimeTypeCache[url]!;
|
if (cachedMimeType && !ignoreCache) {
|
||||||
|
return cachedMimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -722,10 +723,12 @@ export class CoreWSProvider {
|
||||||
*/
|
*/
|
||||||
protected processRetryQueue(): void {
|
protected processRetryQueue(): void {
|
||||||
if (this.retryCalls.length > 0 && this.retryTimeout == 0) {
|
if (this.retryCalls.length > 0 && this.retryTimeout == 0) {
|
||||||
const call = this.retryCalls.shift();
|
const call = this.retryCalls[0];
|
||||||
|
this.retryCalls.shift();
|
||||||
|
|
||||||
// Add a delay between calls.
|
// Add a delay between calls.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
call!.deferred.resolve(this.performPost(call!.method, call!.siteUrl, call!.data, call!.preSets));
|
call.deferred.resolve(this.performPost(call.method, call.siteUrl, call.data, call.preSets));
|
||||||
this.processRetryQueue();
|
this.processRetryQueue();
|
||||||
}, 200);
|
}, 200);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue