Expose last index time in graph

This commit is contained in:
Jordan Eldredge 2023-01-25 14:37:29 -08:00
parent 51fbd7fdfa
commit e53fadb63f
4 changed files with 34 additions and 0 deletions

View file

@ -35,4 +35,12 @@ export default class ClassicSkinResolver
const reviews = await this._model.getReviews();
return reviews.map((row) => new ReviewResolver(row));
}
async last_algolia_index_update_date() {
const updates = await this._model.getAlgoliaIndexUpdates(1);
if (updates.length < 1) {
return null;
}
const update = updates[0];
return new Date(update.update_timestamp * 1000).toISOString();
}
}

View file

@ -221,6 +221,12 @@ type ClassicSkin implements Skin & Node {
reivew page, or via the Discord bot.
"""
reviews: [Review]
"""
The date on which this skin was last updated in the Algolia search index.
Given in simplified extended ISO format (ISO 8601).
"""
last_algolia_index_update_date: String
}
"""

View file

@ -370,6 +370,10 @@ export default class SkinModel {
);
}
async getAlgoliaIndexUpdates(limit?: number): Promise<any[]> {
return Skins.searchIndexUpdatesForSkin(this.getMd5(), limit);
}
async withScreenshotTempFile<T>(
cb: (file: string) => Promise<T>
): Promise<T> {

View file

@ -342,6 +342,22 @@ export async function getSkinsToShoot(limit: number): Promise<string[]> {
return results.map((row) => row.md5);
}
export async function searchIndexUpdatesForSkin(
md5: string,
limit?: number
): Promise<
Array<{ skin_md5: string; update_timestamp: number; field: string }>
> {
let query = knex("algolia_field_updates")
.where({ skin_md5: md5 })
.orderBy("update_timestamp", "desc");
if (limit != null) {
query = query.limit(limit);
}
return query.select();
}
export async function recordSearchIndexUpdates(
md5: string,
fields: string[]