@@ -10,32 +10,34 @@ export class ConfluenceLoader extends BaseLoader<{ type: 'ConfluenceLoader' }, {
10
10
11
11
private readonly confluence : ConfluenceClient ;
12
12
private readonly confluenceBaseUrl : string ;
13
- private readonly spaceNames : string [ ] ;
13
+ private readonly spaceName : string ;
14
+
15
+ private readonly lastUpdatedFilter ?: Date ;
14
16
15
17
constructor ( {
16
- spaceNames ,
18
+ spaceName ,
17
19
confluenceBaseUrl,
18
20
confluenceUsername,
19
21
confluenceToken,
20
22
chunkSize,
21
23
chunkOverlap,
24
+ options,
22
25
} : {
23
- spaceNames : [ string , ... string [ ] ] ;
26
+ spaceName : string ;
24
27
confluenceBaseUrl ?: string ;
25
28
confluenceUsername ?: string ;
26
29
confluenceToken ?: string ;
27
30
chunkSize ?: number ;
28
31
chunkOverlap ?: number ;
32
+ options ?: {
33
+ lastUpdatedFilter : Date ;
34
+ } ;
29
35
} ) {
30
- super (
31
- `ConfluenceLoader_${ md5 ( spaceNames . sort ( ) . join ( ',' ) ) } ` ,
32
- { spaceNames } ,
33
- chunkSize ?? 2000 ,
34
- chunkOverlap ?? 200 ,
35
- ) ;
36
-
37
- this . spaceNames = spaceNames ;
36
+ super ( `ConfluenceLoader_${ md5 ( spaceName ) } ` , { spaceName } , chunkSize ?? 2000 , chunkOverlap ?? 200 ) ;
37
+
38
+ this . spaceName = spaceName ;
38
39
this . confluenceBaseUrl = confluenceBaseUrl ?? process . env . CONFLUENCE_BASE_URL ;
40
+ this . lastUpdatedFilter = options ?. lastUpdatedFilter ?? null ;
39
41
40
42
this . confluence = new ConfluenceClient ( {
41
43
host : this . confluenceBaseUrl ,
@@ -49,16 +51,13 @@ export class ConfluenceLoader extends BaseLoader<{ type: 'ConfluenceLoader' }, {
49
51
}
50
52
51
53
override async * getUnfilteredChunks ( ) {
52
- for ( const spaceKey of this . spaceNames ) {
53
- let count = 0 ;
54
-
55
- for await ( const result of this . processSpace ( spaceKey ) ) {
56
- yield result ;
57
- count ++ ;
58
- }
59
-
60
- this . debug ( `Space '${ spaceKey } ' had ${ count } new pages` ) ;
54
+ let count = 0 ;
55
+ for await ( const result of this . processSpace ( this . spaceName ) ) {
56
+ yield result ;
57
+ count ++ ;
61
58
}
59
+
60
+ this . debug ( `Space '${ this . spaceName } ' had ${ count } new pages` ) ;
62
61
}
63
62
64
63
private async * processSpace ( spaceKey : string ) {
@@ -84,13 +83,26 @@ export class ConfluenceLoader extends BaseLoader<{ type: 'ConfluenceLoader' }, {
84
83
let confluenceVersion = 0 ;
85
84
86
85
try {
87
- const spaceProperties = await this . confluence . content . getContentById ( {
86
+ const pageProperties = await this . confluence . content . getContentById ( {
88
87
id : pageId ,
89
- expand : [ 'version' ] ,
88
+ expand : [ 'version' , 'history' ] ,
90
89
} ) ;
91
90
92
- if ( ! spaceProperties . version . number ) throw new Error ( 'Version number not found in space properties...' ) ;
93
- confluenceVersion = spaceProperties . version . number ;
91
+ if ( this . lastUpdatedFilter ) {
92
+ const pageLastEditDate = new Date ( pageProperties . history . lastUpdated . when ) ;
93
+
94
+ if ( pageLastEditDate > this . lastUpdatedFilter ) {
95
+ this . debug ( `Page '${ title } ' has last edit date ${ pageLastEditDate } . Continuing...` ) ;
96
+ } else {
97
+ this . debug (
98
+ `Page '${ title } ' has last edit date ${ pageLastEditDate } , which is less than filter date. Skipping...` ,
99
+ ) ;
100
+ return ;
101
+ }
102
+ }
103
+
104
+ if ( ! pageProperties . version . number ) throw new Error ( 'Version number not found in page properties...' ) ;
105
+ confluenceVersion = pageProperties . version . number ;
94
106
} catch ( e ) {
95
107
this . debug ( 'Could not get page properties. Page will be SKIPPED!' , title , e . response ) ;
96
108
return ;
0 commit comments