-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(posts): Keep the cache warm – pull once every hour.
Per 1646ace.
- Loading branch information
1 parent
a0d9c10
commit 41729f1
Showing
11 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import _ from "lodash"; | ||
import logger from "../lib/logger"; | ||
import {initializePhotoSources} from "./photoSources"; | ||
|
||
const cachePhotos = photoSearchParams => { | ||
return initializePhotoSources() | ||
.then(photoSources => { | ||
return Promise.all( | ||
photoSources.map((photoSource) => { | ||
return photoSource.getServicePosts(photoSearchParams) | ||
.catch((error) => { | ||
logger.error(error); | ||
return []; | ||
}); | ||
}) | ||
); | ||
}) | ||
.then(_.flatten) | ||
.then(flattenedPhotos => { | ||
return _.sortBy(flattenedPhotos, [ | ||
post => -1 * (post.dateCreated ? post.dateCreated.valueOf() : post.datePublished ? post.datePublished.valueOf() : 0) | ||
]); | ||
}); | ||
}; | ||
|
||
export default cachePhotos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import cachePhotos from "../../photos/cachePhotos"; | ||
import configureEnvironment from "../util/configureEnvironment"; | ||
import responseBuilder from "../util/responseBuilder"; | ||
import returnErrorResponse from "../util/returnErrorResponse"; | ||
|
||
export default (event, context, callback) => { | ||
configureEnvironment() | ||
.then(() => { | ||
return cachePhotos() | ||
.then(sortedPhotos => callback(null, responseBuilder(sortedPhotos))); | ||
}) | ||
.catch(returnErrorResponse(callback)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import cacheWords from "../../words/cacheWords"; | ||
import configureEnvironment from "../util/configureEnvironment"; | ||
import responseBuilder from "../util/responseBuilder"; | ||
import returnErrorResponse from "../util/returnErrorResponse"; | ||
|
||
export default (event, context, callback) => { | ||
configureEnvironment() | ||
.then(() => { | ||
return cacheWords() | ||
.then(sortedWords => callback(null, responseBuilder(sortedWords))); | ||
}) | ||
.catch(returnErrorResponse(callback)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require("../util/configureEnvironment"); | ||
|
||
module.exports = require("./cachePhotos"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require("../util/configureEnvironment"); | ||
|
||
module.exports = require("./cacheWords"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import _ from "lodash"; | ||
import logger from "../lib/logger"; | ||
import {initializeWordSources} from "./wordSources"; | ||
|
||
const cacheWords = wordSearchParams => { | ||
return initializeWordSources() | ||
.then(wordSources => { | ||
return Promise.all( | ||
wordSources.map((wordSource) => { | ||
return wordSource.getServicePosts(wordSearchParams) | ||
.catch((error) => { | ||
logger.error(error); | ||
return []; | ||
}); | ||
}) | ||
); | ||
}) | ||
.then(_.flatten) | ||
.then(flattenedWords => { | ||
return _.sortBy(flattenedWords, [ | ||
post => -1 * (post.dateCreated ? post.dateCreated.valueOf() : post.datePublished ? post.datePublished.valueOf() : 0) | ||
]); | ||
}); | ||
}; | ||
|
||
export default cacheWords; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters