From 2e4724d4dc541c36efe88963fb16c0092926682d Mon Sep 17 00:00:00 2001 From: noodleofdeath Date: Sun, 15 Oct 2023 16:28:11 -0400 Subject: [PATCH] fix(RL-72): throttle materialized view update --- .../ios/Models/PublicSummaryAttributes.swift | 6 ++++- .../ios/ReadLess.xcodeproj/project.pbxproj | 4 ++-- .../schema/resources/summary/Summary.model.ts | 22 ++++++------------- src/server/src/worker/MediaWorker.ts | 13 ++++++----- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/mobile/ios/Models/PublicSummaryAttributes.swift b/src/mobile/ios/Models/PublicSummaryAttributes.swift index 6d79d993..bd1435cc 100644 --- a/src/mobile/ios/Models/PublicSummaryAttributes.swift +++ b/src/mobile/ios/Models/PublicSummaryAttributes.swift @@ -94,7 +94,11 @@ public class Summary { } public var primaryImageUrl: URL? { - return URL(string: (media?["imageArticle"] ?? media?["imageAi1"] ?? imageUrl ?? "") + "@sm") + return URL(string: (media?["imageArticle@sm"] ?? + media?["imageAi1@sm"] ?? + media?["imageArticle"] ?? + media?["imageAi1"] ?? + imageUrl ?? "")) } public init(_ summary: PublicSummaryAttributes) { diff --git a/src/mobile/ios/ReadLess.xcodeproj/project.pbxproj b/src/mobile/ios/ReadLess.xcodeproj/project.pbxproj index ff25a54b..e6a75dcb 100644 --- a/src/mobile/ios/ReadLess.xcodeproj/project.pbxproj +++ b/src/mobile/ios/ReadLess.xcodeproj/project.pbxproj @@ -1915,7 +1915,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.17.0; + MARKETING_VERSION = 1.16.6; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -1956,7 +1956,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.17.0; + MARKETING_VERSION = 1.16.6; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", diff --git a/src/server/src/api/v1/schema/resources/summary/Summary.model.ts b/src/server/src/api/v1/schema/resources/summary/Summary.model.ts index fad9f981..27299a3e 100644 --- a/src/server/src/api/v1/schema/resources/summary/Summary.model.ts +++ b/src/server/src/api/v1/schema/resources/summary/Summary.model.ts @@ -13,7 +13,6 @@ import { } from './Summary.types'; import { SummaryInteraction } from './SummaryInteraction.model'; import { SummaryMedia } from './SummaryMedia.model'; -import { SummaryMediaAttributes } from './SummaryMedia.types'; import { SummaryRelation } from './SummaryRelation.model'; import { SummarySentiment } from './SummarySentiment.model'; import { PublicSummarySentimentAttributes } from './SummarySentiment.types'; @@ -70,10 +69,6 @@ class Size { } -type DownsampleOptions = Pick & { - sizes?: Size[]; -}; - function parseTimeInterval(str: string) { const matches = str.match(/(\d+)\s*(months?|m(?:in(?:ute)?s?)?|h(?:(?:ou)?rs?)?|d(?:ays?)?|w(?:(?:ee)?ks?)?|y(?:(?:ea)?rs?)?)/i); if (matches && matches[1] && matches[2]) { @@ -514,19 +509,16 @@ export class Summary extends Post } async generateThumbnails( - { - key, - parentId, - path, - sizes = [Size.xs, Size.sm, Size.md, Size.lg], - }: DownsampleOptions, - folder: string + sizes = [Size.xs, Size.sm, Size.md, Size.lg], + folder = 'img/s' ) { // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { + console.log('generating thumbnails'); const allMedia = await SummaryMedia.findAll({ where: { parentId: this.id } }); const results: SummaryMedia[] = []; for (const [i, m] of allMedia.entries()) { + console.log(`generating thumbnails for ${m.path}`); if (!/^img\/s/.test(m.path) || /@(?:xs|sm|md|lg|x+l)\.\w+$/.test(m.path)) { continue; } @@ -536,11 +528,11 @@ export class Summary extends Post return; } for (const [j, size] of sizes.entries()) { - const subkey = `${key}@${size.name}`; + const subkey = `${m.key}@${size.name}`; const media = await SummaryMedia.findOne({ where: { key: subkey, - parentId, + parentId: this.id, }, }); if (media) { @@ -569,7 +561,7 @@ export class Summary extends Post }); const media = await SummaryMedia.create({ key: subkey, - parentId, + parentId: this.id, path: response.key, type: 'image', url: response.url, diff --git a/src/server/src/worker/MediaWorker.ts b/src/server/src/worker/MediaWorker.ts index 083d8e8a..f82f78e3 100644 --- a/src/server/src/worker/MediaWorker.ts +++ b/src/server/src/worker/MediaWorker.ts @@ -1,3 +1,4 @@ +import ms from 'ms'; import sharp from 'sharp'; import { Summary, SummaryMedia } from '../api/v1/schema/models'; @@ -100,6 +101,13 @@ export async function doWork() { try { const items = await S3Service.listObjects(); console.log(items.length); + setInterval(async () => { + try { + await Summary.refreshViews(); + } catch (e) { + console.error(e); + } + }, ms('3m')); for (const item of items) { if (/^img\/s/.test(item)) { const media = await SummaryMedia.findOne({ where: { path: item } }); @@ -117,11 +125,6 @@ export async function doWork() { folders.pop(); try { await downsampleImage(media, folders.join('/')); - try { - await Summary.refreshViews(); - } catch (e) { - console.error(e); - } } catch (e) { console.error(e); }