<commit_before>"use strict";
import DesignDocumentMigration from "../helpers/DesignDocumentMigration.js";
import Migration from "../Migration.js";
import CouchClient from "../../CouchClient.js";

export default class ModifyImageUrlToImagesArray {
    constructor(dbName, accessToken) {
        this.dbName = dbName;
        this.designDocumentMigObj = DesignDocumentMigration.instance(dbName, accessToken, "_design/category");
        this.couchClient = CouchClient.instance(dbName, accessToken);
    }

    up() {
        return new Promise((resolve, reject) => {
            Migration.logger(this.dbName).info("ModifyImageUrlToImagesArray::up - started");
            this.designDocumentMigObj.addOrUpdateViews(this._filterViews()).then(res => {
                Migration.logger(this.dbName).info("ModifyImageUrlToImagesArray::up - response %j", res);
                this.couchClient.get("/" + this.dbName + "/_design/category/_view/imageContentFeeds").then((response) => {
                    let feeds = response.rows;
                    for(let feed of feeds) {
                        feed.value.images = [{ "url": feed.value.url }];
                         this.couchClient.saveDocument(feed.value._id, feed.value);
                    }
                }).catch(error => {
                    Migration.logger(this.dbName).error("ModifyImageUrlToImagesArray::up - error %j", error);
                    reject(error);
                });
                resolve(res);
            }).catch(error => {
                Migration.logger(this.dbName).error("ModifyImageUrlToImagesArray::up - error %j", error);
                reject(error);
            });
        });
    }

    _filterViews() {
        return {
            "imageContentFeeds": {
                "map": "function(doc) { if(doc.type == 'imagecontent' && doc.url) {emit(doc._id, doc)} }"
            }
        };

    }
}
<commit_msg>[Mur/Rav] - fixed eslint error in migration<commit_after>"use strict";
import DesignDocumentMigration from "../helpers/DesignDocumentMigration.js";
import Migration from "../Migration.js";
import CouchClient from "../../CouchClient.js";

export default class ModifyImageUrlToImagesArray {
    constructor(dbName, accessToken) {
        this.dbName = dbName;
        this.designDocumentMigObj = DesignDocumentMigration.instance(dbName, accessToken, "_design/category");
        this.couchClient = CouchClient.instance(dbName, accessToken);
    }

    up() {
        return new Promise((resolve, reject) => {
            Migration.logger(this.dbName).info("ModifyImageUrlToImagesArray::up - started");
            this.designDocumentMigObj.addOrUpdateViews(this._filterViews()).then(res => {
                Migration.logger(this.dbName).info("ModifyImageUrlToImagesArray::up - response %j", res);
                this.couchClient.get("/" + this.dbName + "/_design/category/_view/imageContentFeeds").then((response) => {
                    let feeds = response.rows;
                    for(let feed of feeds) {
                        feed.value.images = [{ "url": feed.value.url }];
                        this.couchClient.saveDocument(feed.value._id, feed.value);
                    }
                }).catch(error => {
                    Migration.logger(this.dbName).error("ModifyImageUrlToImagesArray::up - error %j", error);
                    reject(error);
                });
                resolve(res);
            }).catch(error => {
                Migration.logger(this.dbName).error("ModifyImageUrlToImagesArray::up - error %j", error);
                reject(error);
            });
        });
    }

    _filterViews() {
        return {
            "imageContentFeeds": {
                "map": "function(doc) { if(doc.type == 'imagecontent' && doc.url) {emit(doc._id, doc)} }"
            }
        };

    }
}

{'fraction_non_alphanumeric': 0.13680104031209364, 'fraction_numerical': 0.0, 'mean_word_length': 2.071884984025559, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3873453', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1030, 'n_words': 163}