@@ -10,7 +10,6 @@ const controllers = require('./lib/controllers');
1010const routeHelpers = require . main . require ( './src/routes/helpers' ) ;
1111const socketHelpers = require . main . require ( './src/socket.io/helpers' ) ;
1212const topics = require . main . require ( './src/topics' ) ;
13- const posts = require . main . require ( './src/posts' ) ;
1413const user = require . main . require ( './src/user' ) ;
1514const messaging = require . main . require ( './src/messaging' ) ;
1615const api = require . main . require ( './src/api' ) ;
@@ -277,6 +276,38 @@ plugin.filterTopicThreadTools = async (hookData) => {
277276 return hookData ;
278277} ;
279278
279+ plugin . actionTopicReply = async ( hookData ) => {
280+ await summary . clearTopicSummary ( [ hookData . post . tid ] ) ;
281+ } ;
282+
283+ plugin . actionPostEdit = async ( hookData ) => {
284+ await summary . clearTopicSummary ( [ hookData . post . tid ] ) ;
285+ } ;
286+
287+ plugin . actionPostsPurge = async ( hookData ) => {
288+ const { posts } = hookData ;
289+ const uniqTids = [ ...new Set ( posts . map ( p => p . tid ) ) ] ;
290+ await summary . clearTopicSummary ( uniqTids ) ;
291+ } ;
292+
293+ plugin . actionPostRestore = async ( hookData ) => {
294+ await summary . clearTopicSummary ( [ hookData . post . tid ] ) ;
295+ } ;
296+
297+ plugin . actionPostDelete = async ( hookData ) => {
298+ await summary . clearTopicSummary ( [ hookData . post . tid ] ) ;
299+ } ;
300+
301+ plugin . actionPostMove = async ( hookData ) => {
302+ await summary . clearTopicSummary ( [ hookData . post . tid , hookData . tid ] ) ;
303+ } ;
304+
305+ plugin . actionPostChangeOwner = async ( hookData ) => {
306+ const { posts } = hookData ;
307+ const uniqTids = [ ...new Set ( posts . map ( p => p . tid ) ) ] ;
308+ await summary . clearTopicSummary ( uniqTids ) ;
309+ } ;
310+
280311socketPlugins . openai = { } ;
281312
282313socketPlugins . openai . summarizeTopic = async function ( socket , data ) {
@@ -289,5 +320,11 @@ socketPlugins.openai.summarizeTopic = async function (socket, data) {
289320 return ;
290321 }
291322
292- return summary . summarizeTopic ( tid , openai , settings ) ;
323+ let openaiSummary = await topics . getTopicField ( tid , 'openai:summary' ) ;
324+ if ( openaiSummary ) {
325+ return openaiSummary ;
326+ }
327+ openaiSummary = await summary . summarizeTopic ( tid , openai , settings ) ;
328+ await topics . setTopicField ( tid , 'openai:summary' , openaiSummary ) ;
329+ return openaiSummary ;
293330} ;
0 commit comments