@@ -36,6 +36,7 @@ comment: |
3636 var useIndex = ["_design/mangoIndexes2", "cleanup_thumbnail_wallpaper_b64"];
3737 var bookmark = null;
3838 var running = true;
39+ var creatorDisplayCache = {};
3940 while (running) {
4041 context.getRootContext().lastAccessTime = new Date().getTime();
4142 var query = {
@@ -82,17 +83,91 @@ comment: |
8283 if (!docEntry || !docEntry._id) {
8384 continue;
8485 }
85- context.addTextNode(docsNode, "_id", docEntry._id);
86- if (!shouldExecute) {
87- continue;
86+ var docNode = context.addTextNode(docsNode, "document", "");
87+ context.addTextNode(docNode, "_id", docEntry._id);
88+ if (shouldExecute) {
89+ log.warn("Fetching full document " + docEntry._id + " for cleanup processing.");
8890 }
89- log.warn("Fetching full document " + docEntry._id + " for cleanup processing.");
9091 var fullDoc = null;
9192 try {
9293 fullDoc = toJSON(fsclient.getDocument("c8oforms_fs", docEntry._id, new HashMap()));
9394 }
9495 catch (e) {
95- log.error("Failed to fetch document " + docEntry._id + " while preparing cleanup: " + e);
96+ log.error("Failed to fetch document " + docEntry._id + " while preparing cleanup metadata: " + e);
97+ context.addTextNode(docNode, "metadataFetchStatus", "error");
98+ context.addTextNode(errorsNode, "_id", docEntry._id);
99+ continue;
100+ }
101+ if (fullDoc) {
102+ if (hasOwn(fullDoc, "creator") && fullDoc.creator !== undefined && fullDoc.creator !== null) {
103+ var creatorValue = ("" + fullDoc.creator).trim();
104+ if (creatorValue.length > 0) {
105+ context.addTextNode(docNode, "creator", creatorValue);
106+ var cacheKey = creatorValue;
107+ var cachedDisplay = hasOwn(creatorDisplayCache, cacheKey) ? creatorDisplayCache[cacheKey] : undefined;
108+ if (cachedDisplay === undefined) {
109+ var creatorDocId = creatorValue.indexOf("C8Oreserved_") === 0 ? creatorValue : "C8Oreserved_" + creatorValue;
110+ try {
111+ var creatorDoc = toJSON(fsclient.getDocument("c8oforms_fs", creatorDocId, new HashMap()));
112+ if (creatorDoc && hasOwn(creatorDoc, "displayName") && creatorDoc.displayName !== null && creatorDoc.displayName !== undefined) {
113+ cachedDisplay = "" + creatorDoc.displayName;
114+ }
115+ else {
116+ cachedDisplay = "";
117+ }
118+ }
119+ catch (err) {
120+ log.warn("Failed to fetch creator profile " + creatorDocId + " while preparing metadata for " + docEntry._id + ": " + err);
121+ cachedDisplay = "";
122+ }
123+ creatorDisplayCache[cacheKey] = cachedDisplay;
124+ }
125+ var displayNameValue = cachedDisplay !== undefined && cachedDisplay !== null ? "" + cachedDisplay : "";
126+ context.addTextNode(docNode, "creatorDisplayName", displayNameValue);
127+ }
128+ }
129+ if (hasOwn(fullDoc, "name") && fullDoc.name !== undefined && fullDoc.name !== null) {
130+ context.addTextNode(docNode, "name", "" + fullDoc.name);
131+ }
132+ if (hasOwn(fullDoc, "lastMofification") && fullDoc.lastMofification !== undefined && fullDoc.lastMofification !== null) {
133+ var rawLastModification = fullDoc.lastMofification;
134+ var lastModificationMillis = null;
135+ if (typeof rawLastModification === "number") {
136+ lastModificationMillis = rawLastModification;
137+ }
138+ else if (typeof rawLastModification === "string") {
139+ var trimmed = rawLastModification.trim();
140+ if (trimmed.length > 0) {
141+ var parsedMillis = parseInt(trimmed, 10);
142+ if (!isNaN(parsedMillis)) {
143+ lastModificationMillis = parsedMillis;
144+ }
145+ else {
146+ var parsedDate = Date.parse(trimmed);
147+ if (!isNaN(parsedDate)) {
148+ lastModificationMillis = parsedDate;
149+ }
150+ }
151+ }
152+ }
153+ else {
154+ var coerced = +rawLastModification;
155+ if (!isNaN(coerced)) {
156+ lastModificationMillis = coerced;
157+ }
158+ }
159+ if (lastModificationMillis !== null) {
160+ var lastModificationDate = new Date(lastModificationMillis);
161+ if (!isNaN(lastModificationDate.getTime())) {
162+ context.addTextNode(docNode, "lastMofificationDate", "" + lastModificationDate);
163+ }
164+ }
165+ }
166+ }
167+ if (!shouldExecute) {
168+ continue;
169+ }
170+ if (!fullDoc) {
96171 context.addTextNode(errorsNode, "_id", docEntry._id);
97172 continue;
98173 }
@@ -206,4 +281,9 @@ comment: |
206281 value : false
207282↓chunkSize [variables.RequestableVariable-202406070003] :
208283 comment : Number of documents fetched per CouchDB page while iterating.
209- value : 1000
284+ value : 1000
285+ ↓Test_Case_exec [core.TestCase] :
286+ ↓execute [variables.TestCaseVariable-1760444342789] :
287+ value : true
288+ ↓chunkSize [variables.TestCaseVariable-1760444342791] :
289+ value : 1000
0 commit comments