mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-23 00:27:30 +00:00
Ability to store request history in database
This commit is contained in:
parent
a6e7252566
commit
5a3eac338a
@ -64,7 +64,8 @@ let constants = {
|
|||||||
updater_cache_time: 2*60*1000,
|
updater_cache_time: 2*60*1000,
|
||||||
cache_sweep_interval: 3*60*1000,
|
cache_sweep_interval: 3*60*1000,
|
||||||
db_user_id: true,
|
db_user_id: true,
|
||||||
db_post_n3: true
|
db_post_n3: true,
|
||||||
|
db_request_history: false
|
||||||
},
|
},
|
||||||
|
|
||||||
// Instagram uses this stuff. This shouldn't be changed, except to fix a bug that hasn't yet been fixed upstream.
|
// Instagram uses this stuff. This shouldn't be changed, except to fix a bug that hasn't yet been fixed upstream.
|
||||||
@ -122,7 +123,7 @@ let constants = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
database_version: 2
|
database_version: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override values from config and export the result
|
// Override values from config and export the result
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
const constants = require("../constants")
|
||||||
|
const db = require("../db")
|
||||||
|
|
||||||
class RequestHistory {
|
class RequestHistory {
|
||||||
/**
|
/**
|
||||||
* @param {string[]} tracked list of things that can be tracked
|
* @param {string[]} tracked list of things that can be tracked
|
||||||
@ -23,6 +26,9 @@ class RequestHistory {
|
|||||||
const entry = this.store.get(key)
|
const entry = this.store.get(key)
|
||||||
entry.lastRequestAt = Date.now()
|
entry.lastRequestAt = Date.now()
|
||||||
entry.lastRequestSuccessful = success
|
entry.lastRequestSuccessful = success
|
||||||
|
if (constants.caching.db_request_history) {
|
||||||
|
db.prepare("INSERT INTO RequestHistory (type, success, timestamp) VALUES (?, ?, ?)").run(key, +entry.lastRequestSuccessful, entry.lastRequestAt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export() {
|
export() {
|
||||||
|
@ -38,7 +38,18 @@ const deltas = new Map([
|
|||||||
db.prepare("ALTER TABLE Users_New RENAME TO Users")
|
db.prepare("ALTER TABLE Users_New RENAME TO Users")
|
||||||
.run()
|
.run()
|
||||||
})()
|
})()
|
||||||
|
}],
|
||||||
|
// version 2 to version 3
|
||||||
|
[3, function() {
|
||||||
|
db.transaction(() => {
|
||||||
|
db.prepare("DROP TABLE IF EXISTS RequestHistory")
|
||||||
|
.run()
|
||||||
|
db.prepare("CREATE TABLE RequestHistory (type TEXT NOT NULL, success INTEGER NOT NULL, timestamp INTEGER NOT NULL)")
|
||||||
|
.run()
|
||||||
|
})()
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|
||||||
module.exports = async function() {
|
module.exports = async function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user