Skip to content

Commit

Permalink
加入課程清單資料快取機制
Browse files Browse the repository at this point in the history
  • Loading branch information
lyhcode committed May 12, 2012
1 parent 6e0a953 commit e01968d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 32 deletions.
1 change: 1 addition & 0 deletions .foreverignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/public/**
**/.git/**
**/cache/**
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.*
cache
node_modules
ext-4.0.7-gpl
22 changes: 18 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -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 = ''

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"express": "latest"
, "mongoskin": "latest"
, "connect-mongodb": "latest"
, "connect-cache": "latest"
}
}
3 changes: 2 additions & 1 deletion public/modules/SchoolCourse/Store0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
40 changes: 28 additions & 12 deletions public/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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);
}
}
});

Expand Down
4 changes: 3 additions & 1 deletion service/routes/listall.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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));
Expand Down
26 changes: 14 additions & 12 deletions service/routes/listselected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});
10 changes: 10 additions & 0 deletions service/routes/logout.js
Original file line number Diff line number Diff line change
@@ -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
}));
});
4 changes: 2 additions & 2 deletions service/routes/readdata.js
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down

0 comments on commit e01968d

Please sign in to comment.