@@ -34,15 +34,7 @@ import * as dbHelper from './public/firebaseHelper.mjs';
34
34
const PORT = process . env . PORT || 8080 ;
35
35
const RENDER_CACHE = new Map ( ) ; // Cache of pre-rendered HTML pages.
36
36
37
- function updateRSSFeedsDaily ( ) {
38
- console . info ( 'Updating RSS feeds...' ) ;
39
- const dayInMilliseconds = 1000 * 60 * 60 * 24 ;
40
- const tick = Date . now ( ) ;
41
- feeds . updateFeeds ( ) . then ( ( ) => {
42
- console . info ( `feed update took ${ ( Date . now ( ) - tick ) / 1000 } s` ) ;
43
- } ) ;
44
- setTimeout ( updateRSSFeedsDaily , dayInMilliseconds ) ;
45
- }
37
+ const twitter = new Twitter ( 'ChromiumDev' ) ;
46
38
47
39
/**
48
40
*
@@ -143,17 +135,15 @@ app.get('/ssr', async (req, res) => {
143
135
144
136
app . get ( '/tweets/:username' , async ( req , res ) => {
145
137
const username = req . params . username ;
146
- const twitter = new Twitter ( ) ;
147
138
res . status ( 200 ) . json ( await twitter . getTweets ( username ) ) ;
148
139
} ) ;
149
140
150
- app . get ( '/admin/_updaterss ' , async ( req , res ) => {
141
+ app . get ( '/admin/update/rss ' , async ( req , res ) => {
151
142
res . status ( 200 ) . json ( await feeds . updateFeeds ( ) ) ;
152
143
} ) ;
153
144
154
- app . get ( '/admin/_updatetweets ' , async ( req , res ) => {
145
+ app . get ( '/admin/update/tweets/:username ' , async ( req , res ) => {
155
146
const username = req . params . username ;
156
- const twitter = new Twitter ( ) ;
157
147
res . status ( 200 ) . json ( await twitter . updateTweets ( username ) ) ;
158
148
} ) ;
159
149
@@ -206,5 +196,14 @@ app.get('/posts/:year?/:month?/:day?', async (req, res) => {
206
196
app . listen ( PORT , ( ) => {
207
197
console . log ( `App listening on port ${ PORT } ` ) ;
208
198
console . log ( 'Press Ctrl+C to quit.' ) ;
209
- updateRSSFeedsDaily ( ) ;
210
- } ) ;
199
+
200
+ async function updatePosts ( updateFunction , msTimeout ) {
201
+ await updateFunction . bind ( twitter ) . call ( ) ;
202
+ setTimeout ( updatePosts , msTimeout ) ;
203
+ }
204
+
205
+ // Warm the caches.
206
+ // TODO: move to cron.
207
+ updatePosts ( feeds . updateFeeds , 1000 * 60 * 60 * 24 ) ; // every 24hrs
208
+ updatePosts ( twitter . updateTweets , 1000 * 60 * 60 * 1 ) ; // every 1hrs
209
+ } ) ;
0 commit comments