Add /api/v1/offline/prefetch endpoint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-10-28 23:08:23 -05:00
parent 55a22a4f4c
commit f273fc5d9b
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 38 additions and 0 deletions

View File

@ -6,6 +6,42 @@ class OfflineController extends Controller {
return [...super.services, 'models', 'controllers', 'app'] return [...super.services, 'models', 'controllers', 'app']
} }
async do_prefetch(req, res, next) {
const PageModel = this.models.get('api:Page')
const PageNode = this.models.get('api:Node')
const Codium = this.models.get('api:Codium')
const Database = this.models.get('api:db:Database')
const ColumnDef = this.models.get('api:db:ColumnDef')
const DBEntry = this.models.get('api:db:DBEntry')
const FileGroup = this.models.get('api:FileGroup')
const pages = (await PageModel.visible_by_user(req.user)).filter(x => x.Active)
const page_uuids = pages.map(x => x.UUID)
const pageNodes = await PageNode.find({ PageId: { $in: page_uuids }})
const codiums = await Codium.find({ PageId: { $in: page_uuids }, Active: true })
const databases = await Database.find({ PageId: { $in: page_uuids }, Active: true })
const database_uuids = databases.map(x => x.UUID)
const databaseColumns = await ColumnDef.find({ DatabaseId: { $in: database_uuids }})
const databaseEntries = await DBEntry.find({ DatabaseId: { $in: database_uuids }})
const fileGroups = await FileGroup.find({ PageId: { $in: page_uuids }})
return res.api({
pages,
pageNodes,
codiums,
databases,
databaseColumns,
databaseEntries,
fileGroups,
})
}
async do_sync(req, res, next) { async do_sync(req, res, next) {
// TODO account for modify date to not overwrite more recent data!! // TODO account for modify date to not overwrite more recent data!!

View File

@ -47,6 +47,8 @@ const index = {
'/data/export/html': ['controller::Export.html_export'], '/data/export/html': ['controller::Export.html_export'],
'/search': ['controller::api:v1:Misc.get_search'], '/search': ['controller::api:v1:Misc.get_search'],
'/offline/prefetch': ['controller::api:v1:Offline.do_prefetch'],
}, },
post: { post: {