-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Migrate document processor to class #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
server/endpoints/workspaces.jsInstead of creating a new instance of the CollectorApi class every time a method is called, consider creating a single instance and reusing it. This will reduce the overhead of object creation and garbage collection. // Create a single instance of CollectorApi
const collector = new CollectorApi();
// Reuse the instance
const processingOnline = await collector.online();server/endpoints/api/document/index.jsConsider adding error handling in the CollectorApi methods. This will ensure that any errors that occur during the execution of these methods are properly caught and handled, preventing the application from crashing unexpectedly. class CollectorApi {
async processDocument(originalname) {
try {
// existing code
} catch (error) {
console.error(`Error processing document: ${error}`);
throw error;
}
}
// Do the same for other methods
}Consider using a singleton pattern for the CollectorApi class. This will ensure that only one instance of the CollectorApi class is created, which can improve performance by reducing the overhead of creating new instances. class CollectorApi {
constructor() {
if (!CollectorApi.instance) {
CollectorApi.instance = this;
}
return CollectorApi.instance;
}
// existing methods
} |
| } = require("../models/workspacesSuggestedMessages"); | ||
| const { validWorkspaceSlug } = require("../utils/middleware/validWorkspace"); | ||
| const { convertToChatHistory } = require("../utils/helpers/chat/responses"); | ||
| const { CollectorApi } = require("../utils/collectorApi"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a single instance of CollectorApi and reuse it to reduce the overhead of object creation and garbage collection.
| const { CollectorApi } = require("../utils/collectorApi"); | |
| const Collector = new CollectorApi(); |
| } | ||
| */ | ||
| try { | ||
| const Collector = new CollectorApi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CollectorApi class is now a singleton, ensuring only one instance is created. This improves performance by reducing the overhead of creating new instances.
| const Collector = new CollectorApi(); | |
| class CollectorApi { | |
| constructor() { | |
| if (!CollectorApi.instance) { | |
| CollectorApi.instance = this; | |
| } | |
| return CollectorApi.instance; | |
| } | |
| // existing methods | |
| } |
* Migrate document processor to class * forgot "new"
Pull Request Type
Migrating Document processor from single functions to a class instance for future use and easier dev interfacing