Permalink
Browse files

加入課程清單資料快取機制

  • Loading branch information...
lyhcode committed May 12, 2012
1 parent 6e0a953 commit e01968d47b2fdda2864ed225a1c57b52e65ec743
View
@@ -1,2 +1,3 @@
**/public/**
**/.git/**
+**/cache/**
View
@@ -1,3 +1,4 @@
.*
+cache
node_modules
ext-4.0.7-gpl
View
22 app.js
@@ -1,15 +1,29 @@
-
/**
-* Module dependencies.
-*/
+ * 網路選課系統
+ * Powerd by ExtJS + Node.js + MongoDB
+ *
+ * @author lyhcode@gmail.com
+ */
+
+
+// Module dependencies.
var express = require('express')
, routes = require('./routes')
+ , cache = require('connect-cache')
, mongo = require('mongoskin')
, db = mongo.db('guest:guest@staff.mongohq.com:10028/acad_taj?auto_reconnect=true&poolSize=5')
, mongoStore = require('connect-mongodb');
-var app = module.exports = express.createServer();
+// Express web server
+
+var app = module.exports = express.createServer(
+ cache({rules: [
+ {regex: /\/cached\/.*/, ttl: 60*60*1000}
+ ]})
+);
+
+// URL prefix setup for additional path like iisnode
var urlprefix = ''
View
@@ -17,5 +17,6 @@
"express": "latest"
, "mongoskin": "latest"
, "connect-mongodb": "latest"
+ , "connect-cache": "latest"
}
}
@@ -12,8 +12,9 @@ Ext.define('Module.SchoolCourse.Store0', {
],
proxy: {
type: 'ajax',
- url: __SERVICE_URL + '/service/listall.json',
+ url: __SERVICE_URL + '/service/cached/listall.json',
method: 'GET',
+ noCache: false,
reader: {
type: 'array'
}
View
@@ -125,12 +125,17 @@ Ext.onReady(function(){
'是否登出系統',
'<span class="portal-message">請按「是」確認登出系統,按「否」則取消!</span>',
function (btn, text) {
- if (btn=='yes') {
- location.href = 'login.html';
+ if (btn == 'yes') {
+ Ext.Ajax.request({
+ url: __SERVICE_URL + '/service/logout.json',
+ method: 'GET',
+ success: function(response) {
+ location.href = 'login.html';
+ }
+ });
}
}
);
-
}
}],
items: [{
@@ -229,18 +234,29 @@ Ext.onReady(function(){
success: function(response) {
var obj = Ext.JSON.decode(response.responseText);
- if (obj.data) {
- ClientSession.user = obj.data.user;
+ if (!obj.success) {
+ Ext.Msg.alert(
+ '發生錯誤',
+ '請重新登入再操作一次!',
+ function() {
+ location.href = 'login.html';
+ }
+ );
+ }
+ else {
+ if (obj.data) {
+ ClientSession.user = obj.data.user;
- //更新使用者資訊列
- if (obj.data.user) {
- var user = obj.data.user;
- var cmp = Ext.getCmp('userinfo');
- cmp.setText(user.chtname+' '+user.studentno+' '+user.classname);
+ //更新使用者資訊列
+ if (obj.data.user) {
+ var user = obj.data.user;
+ var cmp = Ext.getCmp('userinfo');
+ cmp.setText(user.chtname+' '+user.studentno+' '+user.classname);
+ }
}
- }
- completeJob(0);
+ completeJob(0);
+ }
}
});
@@ -1,4 +1,4 @@
-app.get(urlprefix + '/service/listall.json', function(req, res) {
+app.get(urlprefix + '/service/cached/listall.json', function(req, res) {
res.charset = 'UTF-8';
res.contentType('application/json');
@@ -8,6 +8,8 @@ app.get(urlprefix + '/service/listall.json', function(req, res) {
'roomname':1, 'maxcount':1, 'selectedcount': 1,
'unitid': 1, 'collegeid': 1, 'studytype': 1
};
+
+ console.log('Query tSemesterCusWeb from MongoDB '+new Date());
db.collection('tSemesterCusWeb').find({}, fields).toArray(function(err, rows){
//res.send(JSON.stringify(rows));
@@ -9,18 +9,20 @@ app.get(urlprefix + '/service/listselected.json', function(req, res) {
//學生資料(SESSION)
var user = req.session.user;
- //查詢條件
- var where = {
- studentid: user.studentid
- };
+ if (user) {
+ //查詢條件
+ var where = {
+ studentid: user.studentid
+ };
- //SELECT * FROM tSelectedSemCus WHERE studentid=?
- db.collection('tSelectedSemCus').find(where).toArray(function(err, rows){
- var arr = new Array();
- rows.forEach(function(item) {
- arr.push(item.semcourseid);
+ //SELECT * FROM tSelectedSemCus WHERE studentid=?
+ db.collection('tSelectedSemCus').find(where).toArray(function(err, rows){
+ var arr = new Array();
+ rows.forEach(function(item) {
+ arr.push(item.semcourseid);
+ });
+ res.send(JSON.stringify(arr));
+ res.end();
});
- res.send(JSON.stringify(arr));
- res.end();
- });
+ }
});
View
@@ -0,0 +1,10 @@
+app.get(urlprefix + '/service/logout.json', function(req, res) {
+ res.charset = 'UTF-8';
+ res.contentType('application/json');
+
+ req.session.user = null;
+
+ res.send(JSON.stringify({
+ success: true
+ }));
+});
@@ -1,9 +1,9 @@
app.get(urlprefix + '/service/readdata.json', function(req, res) {
res.charset = 'UTF-8';
res.contentType('application/json');
-
+
var results = {
- success: true,
+ success: req.session.user?true:false,
data: {
user: req.session.user
}

0 comments on commit e01968d

Please sign in to comment.