Avatars cache: don't consider updatedTimestamp field
The updatedTimestamp field doesn't reflect when the thread was last
modified (sometimes a new reply is added and the timestamp doesn't
change), so this change stops adding it to the cache and considering
only the lastMessageId field in order to determine whether a cache entry
is still valid or not.
Bug: twpowertools:11
Change-Id: I64dd8b8fc25b431bb5294f6aa59b014f1084d758
diff --git a/src/contentScripts/communityConsole/avatars.js b/src/contentScripts/communityConsole/avatars.js
index 5e5eeee..ddc6e3c 100644
--- a/src/contentScripts/communityConsole/avatars.js
+++ b/src/contentScripts/communityConsole/avatars.js
@@ -125,7 +125,6 @@
// The following fields are useful for the cache and can be
// undefined, but this is checked before adding an entry to the
// cache.
- updatedTimestamp: data?.['1']?.['2']?.['1']?.['4'],
lastMessageId: data?.['1']?.['2']?.['10'],
};
});
@@ -136,8 +135,6 @@
return this.getFirstMessages(thread).then(result => {
var messages = result.messages;
var author = result.author;
- var updatedTimestamp =
- Math.floor(Number.parseInt(result.updatedTimestamp) / 1000000);
var lastMessageId = result.lastMessageId;
var avatarUrls = [];
@@ -154,10 +151,9 @@
}
// Add entry to cache if all the extra metadata could be retrieved.
- if (updatedTimestamp !== undefined && lastMessageId !== undefined)
+ if (lastMessageId !== undefined)
this.db.putCacheEntry({
threadId: thread.thread,
- updatedTimestamp,
lastMessageId,
avatarUrls,
num,
diff --git a/src/contentScripts/communityConsole/utils/AvatarsDB.js b/src/contentScripts/communityConsole/utils/AvatarsDB.js
index a8c155c..ba32fea 100644
--- a/src/contentScripts/communityConsole/utils/AvatarsDB.js
+++ b/src/contentScripts/communityConsole/utils/AvatarsDB.js
@@ -90,20 +90,15 @@
var promises = [];
threads.forEach(t => {
var id = t?.['2']?.['1']?.['1'];
- var currentUpdatedTimestamp =
- Math.floor(Number.parseInt(t?.['2']?.['1']?.['4']) / 1000000);
var currentLastMessageId = t?.['2']?.['10'];
- if (id === undefined || currentUpdatedTimestamp === undefined ||
- currentLastMessageId === undefined)
- return;
+ if (id === undefined || currentLastMessageId === undefined) return;
promises.push(this.getCacheEntry(id).then(entry => {
if (entry === undefined) return;
// If the cache entry is still valid.
- if (currentLastMessageId == entry.lastMessageId ||
- currentUpdatedTimestamp <= entry.updatedTimestamp) {
+ if (currentLastMessageId == entry.lastMessageId) {
entry.lastUsedTimestamp = Math.floor(Date.now() / 1000);
return this.putCacheEntry(entry).catch(err => {
console.error(