Skip to content

Commit ab6db79

Browse files
committed
MOBILE-2178 database: Don't force cache in getAllEntriesIds
1 parent cfa3fc8 commit ab6db79

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

www/addons/mod/data/services/data.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,20 @@ angular.module('mm.addons.mod_data')
307307
*/
308308
self.getEntries = function(dataId, groupId, sort, order, page, perPage, forceCache, ignoreCache, siteId) {
309309
return $mmSitesManager.getSite(siteId).then(function(site) {
310+
// Always use sort and order params to improve cache usage (entries are identified by params).
310311
var params = {
311312
databaseid: dataId,
312313
returncontents: 1,
313314
page: page || 0,
314315
perpage: perPage || mmaModDataPerPage,
315-
groupid: groupId || 0
316+
groupid: groupId || 0,
317+
sort: sort || "0",
318+
order: order || "ASC"
316319
},
317320
preSets = {
318321
cacheKey: getEntriesCacheKey(dataId, groupId)
319322
};
320323

321-
if (typeof sort != "undefined") {
322-
params.sort = sort;
323-
}
324-
325-
if (typeof order !== "undefined") {
326-
params.order = order;
327-
}
328-
329324
if (forceCache) {
330325
preSets.omitExpires = true;
331326
} else if (ignoreCache) {

www/addons/mod/data/services/helper.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,13 @@ angular.module('mm.addons.mod_data')
584584
* @param {Number} dataId Data ID.
585585
* @param {Number} entryId Entry ID.
586586
* @param {Number} groupId Group ID.
587-
* @param {String} siteId Site ID. Current if not defined.
588-
* @return {Promise} Containing page number, if has next and have following page.
587+
* @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.
588+
* @param {Boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
589+
* @param {String} [siteId] Site ID. Current if not defined.
590+
* @return {Promise} Containing page number, if has next and have following page.
589591
*/
590-
self.getPageInfoByEntry = function(dataId, entryId, groupId, siteId) {
591-
return self.getAllEntriesIds(dataId, groupId, siteId).then(function(entries) {
592+
self.getPageInfoByEntry = function(dataId, entryId, groupId, forceCache, ignoreCache, siteId) {
593+
return self.getAllEntriesIds(dataId, groupId, forceCache, ignoreCache, siteId).then(function(entries) {
592594
for (var index in entries) {
593595
if (entries[index] == entryId) {
594596
index = parseInt(index, 10);
@@ -614,11 +616,13 @@ angular.module('mm.addons.mod_data')
614616
* @param {Number} dataId Data ID.
615617
* @param {Number} page Page number.
616618
* @param {Number} groupId Group ID.
617-
* @param {String} siteId Site ID. Current if not defined.
618-
* @return {Promise} Containing page number, if has next and have following page.
619+
* @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.
620+
* @param {Boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
621+
* @param {String} [siteId] Site ID. Current if not defined.
622+
* @return {Promise} Containing page number, if has next and have following page.
619623
*/
620-
self.getPageInfoByPage = function(dataId, page, groupId, siteId) {
621-
return self.getAllEntriesIds(dataId, groupId, siteId).then(function(entries) {
624+
self.getPageInfoByPage = function(dataId, page, groupId, forceCache, ignoreCache, siteId) {
625+
return self.getAllEntriesIds(dataId, groupId, forceCache, ignoreCache, siteId).then(function(entries) {
622626
var index = parseInt(page, 10) - 1,
623627
entryId = entries[index];
624628
if (entryId) {
@@ -642,11 +646,13 @@ angular.module('mm.addons.mod_data')
642646
* @name $mmaModDataHelper#getAllEntriesIds
643647
* @param {Number} dataId Data ID.
644648
* @param {Number} groupId Group ID.
645-
* @param {String} siteId Site ID. Current if not defined.
646-
* @return {Promise} Containing and array of EntryId.
649+
* @param {Boolean} [forceCache] True to always get the value from cache, false otherwise. Default false.
650+
* @param {Boolean} [ignoreCache] True if it should ignore cached data (it will always fail in offline or server down).
651+
* @param {String} [siteId] Site ID. Current if not defined.
652+
* @return {Promise} Resolved with an array of entry ID.
647653
*/
648-
self.getAllEntriesIds = function(dataId, groupId, siteId) {
649-
return $mmaModData.fetchAllEntries(dataId, groupId, undefined, undefined, undefined, true, undefined, undefined, siteId)
654+
self.getAllEntriesIds = function(dataId, groupId, forceCache, ignoreCache, siteId) {
655+
return $mmaModData.fetchAllEntries(dataId, groupId, undefined, undefined, undefined, forceCache, ignoreCache, siteId)
650656
.then(function(entries) {
651657
return entries.map(function(entry) {
652658
return entry.id;

0 commit comments

Comments
 (0)