mirror of https://github.com/calzoneman/sync.git
Add channels.last_loaded column
This commit is contained in:
parent
d62d5e0cab
commit
8f266ccd44
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.32.1",
|
||||
"version": "3.33.0",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -93,10 +93,10 @@ function Channel(name) {
|
|||
if (err && err !== "Channel is not registered") {
|
||||
self.emit("loadFail", "Failed to load channel data from the database. Please try again later.");
|
||||
self.setFlag(Flags.C_ERROR);
|
||||
return;
|
||||
} else {
|
||||
self.initModules();
|
||||
self.loadState();
|
||||
db.channels.updateLastLoaded(self.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -147,8 +147,8 @@ module.exports = {
|
|||
}
|
||||
|
||||
db.query("INSERT INTO `channels` " +
|
||||
"(`name`, `owner`, `time`) VALUES (?, ?, ?)",
|
||||
[name, owner, Date.now()],
|
||||
"(`name`, `owner`, `time`, `last_loaded`) VALUES (?, ?, ?, ?)",
|
||||
[name, owner, Date.now(), new Date()],
|
||||
function (err, res) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
|
@ -641,5 +641,20 @@ module.exports = {
|
|||
}
|
||||
|
||||
db.query("DELETE FROM `channel_bans` WHERE channel=?", [chan], callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the `last_loaded` column to be the current timestamp
|
||||
*/
|
||||
updateLastLoaded: function updateLastLoaded(channelId) {
|
||||
if (channelId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.query("UPDATE channels SET last_loaded = ? WHERE id = ?", [new Date(), channelId], error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to update last_loaded column for channel ID ${channelId}: ${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ var Logger = require("../logger");
|
|||
var Q = require("q");
|
||||
import Promise from 'bluebird';
|
||||
|
||||
const DB_VERSION = 9;
|
||||
const DB_VERSION = 10;
|
||||
var hasUpdates = [];
|
||||
|
||||
module.exports.checkVersion = function () {
|
||||
|
@ -63,6 +63,8 @@ function update(version, cb) {
|
|||
addUsernameDedupeColumn(cb);
|
||||
} else if (version < 9) {
|
||||
populateUsernameDedupeColumn(cb);
|
||||
} else if (version < 10) {
|
||||
addChannelLastLoadedColumn(cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -388,3 +390,21 @@ function populateUsernameDedupeColumn(cb) {
|
|||
})
|
||||
});
|
||||
}
|
||||
|
||||
function addChannelLastLoadedColumn(cb) {
|
||||
db.query("ALTER TABLE channels ADD COLUMN last_loaded TIMESTAMP NOT NULL DEFAULT 0", error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to add last_loaded column: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
db.query("ALTER TABLE channels ADD INDEX i_last_loaded (last_loaded)", error => {
|
||||
if (error) {
|
||||
Logger.errlog.log(`Failed to add index on last_loaded column: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue