mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #19162 from overleaf/jpa-flaky-admin-test
[web] refresh system message cache after creating/deleting message GitOrigin-RevId: f7155e94a8bf08b527e7ae69d9d6a41e54c01282
This commit is contained in:
parent
2e1dcee22b
commit
c04fea0fd3
2 changed files with 14 additions and 12 deletions
|
@ -52,8 +52,6 @@ describe('admin panel', function () {
|
||||||
cy.get('button').contains('Post Message').click()
|
cy.get('button').contains('Post Message').click()
|
||||||
cy.findByText(message)
|
cy.findByText(message)
|
||||||
|
|
||||||
cy.log('wait for system message propagation')
|
|
||||||
cy.wait(13000)
|
|
||||||
const resumeUser1Session = login(user1)
|
const resumeUser1Session = login(user1)
|
||||||
cy.visit('/project')
|
cy.visit('/project')
|
||||||
cy.findByText(message)
|
cy.findByText(message)
|
||||||
|
|
|
@ -6,6 +6,8 @@ const { callbackifyAll } = require('@overleaf/promise-utils')
|
||||||
const logger = require('@overleaf/logger')
|
const logger = require('@overleaf/logger')
|
||||||
|
|
||||||
const SystemMessageManager = {
|
const SystemMessageManager = {
|
||||||
|
_cachedMessages: [],
|
||||||
|
|
||||||
getMessages() {
|
getMessages() {
|
||||||
return this._cachedMessages
|
return this._cachedMessages
|
||||||
},
|
},
|
||||||
|
@ -16,28 +18,30 @@ const SystemMessageManager = {
|
||||||
|
|
||||||
async clearMessages() {
|
async clearMessages() {
|
||||||
await SystemMessage.deleteMany({}).exec()
|
await SystemMessage.deleteMany({}).exec()
|
||||||
|
await this.refreshCache()
|
||||||
},
|
},
|
||||||
|
|
||||||
async createMessage(content) {
|
async createMessage(content) {
|
||||||
const message = new SystemMessage({ content })
|
const message = new SystemMessage({ content })
|
||||||
await message.save()
|
await message.save()
|
||||||
|
await this.refreshCache()
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshCache() {
|
async refreshCache() {
|
||||||
this.getMessagesFromDB()
|
this._cachedMessages = await this.getMessagesFromDB()
|
||||||
.then(messages => {
|
},
|
||||||
this._cachedMessages = messages
|
|
||||||
})
|
refreshCacheInBackground() {
|
||||||
.catch(err => {
|
this.refreshCache().catch(err => {
|
||||||
logger.warn({ err }, 'failed to refresh system messages cache')
|
logger.warn({ err }, 'failed to refresh system messages cache')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const CACHE_TIMEOUT = 10 * 1000 * (Math.random() + 2) // 20-30 seconds
|
const CACHE_TIMEOUT = 10 * 1000 * (Math.random() + 2) // 20-30 seconds
|
||||||
SystemMessageManager.refreshCache()
|
SystemMessageManager.refreshCacheInBackground()
|
||||||
const intervalHandle = setInterval(
|
const intervalHandle = setInterval(
|
||||||
() => SystemMessageManager.refreshCache(),
|
() => SystemMessageManager.refreshCacheInBackground(),
|
||||||
CACHE_TIMEOUT
|
CACHE_TIMEOUT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue