mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-19 16:14:39 +00:00
maintenance (cleanup): dead code elimination: leftover from O(n) initial search
This commit is contained in:
@@ -202,6 +202,3 @@ Data.prototype.destroy = function(){
|
||||
}
|
||||
|
||||
export const cache = new Data();
|
||||
if(typeof WorkerGlobalScope === "undefined"){ // web worker context
|
||||
window.DB = cache;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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))
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user