maintenance (cleanup): dead code elimination: leftover from O(n) initial search

This commit is contained in:
Mickael Kerjean
2019-05-09 00:17:42 +10:00
parent d69aeb47f1
commit 4a2d1d6c3c
4 changed files with 0 additions and 76 deletions
-3
View File
@@ -202,6 +202,3 @@ Data.prototype.destroy = function(){
}
export const cache = new Data();
if(typeof WorkerGlobalScope === "undefined"){ // web worker context
window.DB = cache;
}
-6
View File
@@ -45,10 +45,4 @@ window.addEventListener("DOMContentLoaded", () => {
}
return removeLoader().then(render);
});
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/assets/worker/cache.js').catch(function(error) {
console.log('ServiceWorker registration failed:', error);
});
}
});
-21
View File
@@ -3,7 +3,6 @@ import React from 'react';
import { Files } from '../model/';
import { notify, alert, currentShare } from '../helpers/';
import Path from 'path';
import Worker from "../worker/search.worker.js";
import { Observable } from "rxjs/Observable";
export const sort = function(files, type){
@@ -411,27 +410,7 @@ export const onUpload = function(path, e){
};
const worker = new Worker();
export const onSearch = (keyword, path = "/") => {
if(navigator.onLine == false){
notify.send("Result aren't complete because you're not online", "info");
worker.postMessage({
action: "search::find",
path: path,
share: currentShare(),
keyword: keyword
});
return new Observable((obs) => {
worker.onmessage = (m) => {
if(m.data.type === "search::found"){
obs.next(m.data && m.data.files || []);
}
};
});
}
return new Observable((obs) => {
Files.search(keyword, path).then((f) => obs.next(f))
});
-46
View File
@@ -1,46 +0,0 @@
import { Observable } from 'rxjs/Observable';
import { cache } from '../helpers/cache';
let current_search = null;
self.onmessage = function(message){
if(message.data.action === "search::find"){
if(current_search != null){
current_search.unsubscribe();
}
current_search = Search([message.data.share, message.data.path], message.data.keyword).subscribe((a) => {
self.postMessage({type: "search::found", files: a});
}, null, () => {
self.postMessage({type: "search::completed"})
});
}
}
function Search(key, keyword){
let results = [];
return new Observable((obs) => {
obs.next(results);
const keys = keyword.split(" ").map((e) => e.toLowerCase());
cache.fetchAll((record) => {
const found = record.results.filter((file) => {
for(let i=0, l=keys.length; i<l; i++){
if(file.name.toLowerCase().indexOf(keys[i]) === -1) return false;
}
return true;
});
if(found.length > 0){
results = results.concat(found);
obs.next(results);
}
}, cache.FILE_PATH, [key[0], key[1]]).then(() => {
obs.complete(results);
});
});
}
function Indexing(config){
return;
}