mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	refactor(backend_log): use async readFile
using synchronous functions on the backend is not recommended, as it is "blocking the event loop", i.e. no other tasks get executed/processed, while the file is being read
This commit is contained in:
		
							parent
							
								
									b30164ef66
								
							
						
					
					
						commit
						06ebcc210e
					
				@ -1,15 +1,15 @@
 | 
				
			|||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import fs from "fs";
 | 
					import { readFile  } from "fs/promises";
 | 
				
			||||||
import dateUtils from "../../services/date_utils.js";
 | 
					import dateUtils from "../../services/date_utils.js";
 | 
				
			||||||
import dataDir from "../../services/data_dir.js";
 | 
					import dataDir from "../../services/data_dir.js";
 | 
				
			||||||
const { LOG_DIR } = dataDir;
 | 
					const { LOG_DIR } = dataDir;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getBackendLog() {
 | 
					async function getBackendLog() {
 | 
				
			||||||
    const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`;
 | 
					    const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
        return fs.readFileSync(file, "utf8");
 | 
					        return await readFile(file, "utf8");
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
        // most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
 | 
					        // most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977
 | 
				
			||||||
        return "";
 | 
					        return "";
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user