Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
59280bf3
Commit
59280bf3
authored
Jan 24, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
indexStorage: pass JSLINT
parent
a0aaf798
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
103 deletions
+118
-103
src/jio.storage/indexstorage.js
src/jio.storage/indexstorage.js
+118
-103
No files found.
src/jio.storage/indexstorage.js
View file @
59280bf3
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
jIO
.
addStorageType
(
'
indexed
'
,
function
(
spec
,
my
)
{
jIO
.
addStorageType
(
'
indexed
'
,
function
(
spec
,
my
)
{
"
use strict
"
;
"
use strict
"
;
var
that
,
priv
=
{}
,
spec
;
var
that
,
priv
=
{};
spec
=
spec
||
{};
spec
=
spec
||
{};
that
=
my
.
basicStorage
(
spec
,
my
);
that
=
my
.
basicStorage
(
spec
,
my
);
...
@@ -95,12 +95,12 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -95,12 +95,12 @@ jIO.addStorageType('indexed', function (spec, my) {
* @return {object} The new index array
* @return {object} The new index array
*/
*/
priv
.
createEmptyIndexArray
=
function
(
indices
)
{
priv
.
createEmptyIndexArray
=
function
(
indices
)
{
var
obj
,
i
,
j
=
priv
.
indices
.
length
,
var
i
,
j
=
priv
.
indices
.
length
,
new_index_object
=
{},
new_index_name
;
new_index_object
=
{},
new_index_name
;
if
(
indices
===
undefined
)
{
if
(
indices
===
undefined
)
{
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
j
;
i
+=
1
)
{
new_index_name
=
priv
.
indices
[
i
]
[
"
name
"
]
;
new_index_name
=
priv
.
indices
[
i
]
.
name
;
new_index_object
[
new_index_name
]
=
{};
new_index_object
[
new_index_name
]
=
{};
}
}
}
}
...
@@ -119,6 +119,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -119,6 +119,7 @@ jIO.addStorageType('indexed', function (spec, my) {
var
key
,
obj
,
prop
;
var
key
,
obj
,
prop
;
for
(
key
in
indexToSearch
)
{
for
(
key
in
indexToSearch
)
{
if
(
indexToSearch
.
hasOwnProperty
(
key
))
{
obj
=
indexToSearch
[
key
];
obj
=
indexToSearch
[
key
];
for
(
prop
in
obj
)
{
for
(
prop
in
obj
)
{
if
(
obj
[
prop
]
===
docid
)
{
if
(
obj
[
prop
]
===
docid
)
{
...
@@ -126,8 +127,9 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -126,8 +127,9 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
}
}
return
false
;
}
}
return
false
;
};
/**
/**
* Find id in indices
* Find id in indices
...
@@ -143,39 +145,44 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -143,39 +145,44 @@ jIO.addStorageType('indexed', function (spec, my) {
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
[
"
name
"
]
;
index
.
name
=
index
.
reference
.
name
;
index
.
size
=
priv
.
getObjectSize
(
indices
[
index
.
name
]);
index
.
size
=
priv
.
getObjectSize
(
indices
[
index
.
name
]);
index
.
result_array
;
if
(
index
.
size
>
0
)
{
if
(
index
.
size
>
0
)
{
if
(
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
bool
"
))
{
if
(
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
bool
"
))
{
return
true
return
true
;
};
}
}
}
}
return
false
;
}
}
return
false
;
};
/**
* Clean up indexes when removing a file
* @method cleanIndices
* @param {object} indices The file containing the indeces
* @param {object} doc The document which should be added to the index
* @return {object} indices The cleaned up file
*/
priv
.
cleanIndices
=
function
(
indices
,
doc
)
{
priv
.
cleanIndices
=
function
(
indices
,
doc
)
{
var
i
,
j
,
k
,
index
,
key
,
obj
,
prop
,
l
=
priv
.
indices
.
length
,
var
i
,
j
,
k
,
index
,
key
,
l
=
priv
.
indices
.
length
;
docid
=
doc
.
_id
;
// loop indices (indexA, indexAB...)
// loop indices (indexA, indexAB...)
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
// index object (reference and current-iteration)
// index object (reference and current-iteration)
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current
=
indices
[
index
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
for
(
j
=
0
;
j
<
index
.
current_size
;
j
++
)
{
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
key
=
priv
.
searchIndexByValue
(
index
.
current
,
doc
.
_id
,
"
key
"
);
key
=
priv
.
searchIndexByValue
(
index
.
current
,
doc
.
_id
,
"
key
"
);
index
.
result_array
=
index
.
current
[
key
];
index
.
result_array
=
index
.
current
[
key
];
if
(
!!
key
)
{
if
(
!!
key
)
{
// if there is more than one docid in the result array,
// if there is more than one docid in the result array,
// just remove this one and not the whole array
// just remove this one and not the whole array
if
(
index
.
result_array
.
length
>
1
)
{
if
(
index
.
result_array
.
length
>
1
)
{
index
.
result_array
.
splice
(
k
,
1
);
index
.
result_array
.
splice
(
k
,
1
);
}
else
{
}
else
{
delete
index
.
current
[
key
];
delete
index
.
current
[
key
];
}
}
...
@@ -183,7 +190,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -183,7 +190,7 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
return
indices
;
return
indices
;
}
}
;
/**
/**
* Adds entries to indices
* Adds entries to indices
* @method createEmptyIndexArray
* @method createEmptyIndexArray
...
@@ -191,7 +198,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -191,7 +198,7 @@ jIO.addStorageType('indexed', function (spec, my) {
* @param {object} doc The document which should be added to the index
* @param {object} doc The document which should be added to the index
*/
*/
priv
.
updateIndices
=
function
(
indices
,
doc
)
{
priv
.
updateIndices
=
function
(
indices
,
doc
)
{
var
i
,
j
,
k
,
m
,
index
,
value
,
label
,
key
,
l
=
priv
.
indices
.
length
;
var
i
,
j
,
k
,
m
,
index
,
value
,
label
,
key
,
l
=
priv
.
indices
.
length
;
// loop indices
// loop indices
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
...
@@ -199,14 +206,13 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -199,14 +206,13 @@ jIO.addStorageType('indexed', function (spec, my) {
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
reference_size
=
index
.
reference
.
fields
.
length
;
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
field_array
=
[];
index
.
field_array
=
[];
index
.
current
=
indices
[
index
.
name
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
// build array of values to create entries in index
// build array of values to create entries in index
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
for
(
j
=
0
;
j
<
index
.
reference_size
;
j
+=
1
)
{
label
=
index
.
reference
.
fields
[
j
]
label
=
index
.
reference
.
fields
[
j
]
;
value
=
doc
[
label
];
value
=
doc
[
label
];
if
(
value
!==
undefined
)
{
if
(
value
!==
undefined
)
{
// add a new entry
// add a new entry
...
@@ -215,7 +221,8 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -215,7 +221,8 @@ jIO.addStorageType('indexed', function (spec, my) {
// remove existing entries with same docid
// remove existing entries with same docid
// because items are stored as "keyword:id" pairs this is tricky
// because items are stored as "keyword:id" pairs this is tricky
if
(
index
.
current_size
>
0
)
{
if
(
index
.
current_size
>
0
)
{
key
=
priv
.
searchIndexByValue
(
indices
[
index
.
name
],
doc
.
_id
,
"
key
"
);
key
=
priv
.
searchIndexByValue
(
indices
[
index
.
reference
.
name
],
doc
.
_id
,
"
key
"
);
if
(
!!
key
)
{
if
(
!!
key
)
{
delete
index
.
current
[
key
];
delete
index
.
current
[
key
];
}
}
...
@@ -239,6 +246,9 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -239,6 +246,9 @@ jIO.addStorageType('indexed', function (spec, my) {
return
indices
;
return
indices
;
};
};
priv
.
getDocContent
=
function
()
{
};
/**
/**
* Build the alldocs response from the index file (overriding substorage)
* Build the alldocs response from the index file (overriding substorage)
* @method allDocsResponseFromIndex
* @method allDocsResponseFromIndex
...
@@ -250,35 +260,60 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -250,35 +260,60 @@ jIO.addStorageType('indexed', function (spec, my) {
priv
.
allDocsResponseFromIndex
=
function
(
indices
,
include_docs
,
option
)
{
priv
.
allDocsResponseFromIndex
=
function
(
indices
,
include_docs
,
option
)
{
var
i
,
j
,
k
,
m
,
n
=
0
,
l
=
priv
.
indices
.
length
,
var
i
,
j
,
k
,
m
,
n
=
0
,
l
=
priv
.
indices
.
length
,
index
,
key
,
obj
,
prop
,
found
,
file
,
index
,
key
,
obj
,
prop
,
found
,
file
,
unique_count
=
0
,
unique_docids
=
[],
all_doc_response
=
{};
unique_count
=
0
,
unique_docids
=
[],
all_doc_response
=
{},
success
=
function
(
content
)
{
file
=
{
value
:
{}
};
file
.
id
=
unique_docids
[
n
];
file
.
key
=
unique_docids
[
n
];
file
.
doc
=
content
;
all_doc_response
.
rows
.
push
(
file
);
// async counter, must be in callback
n
+=
1
;
if
(
n
===
unique_count
)
{
that
.
success
(
all_doc_response
);
}
},
error
=
function
()
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Cannot find the document
"
,
"
reason
"
:
"
Cannot get a document from substorage
"
});
return
;
};
// loop indices
// loop indices
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
index
=
{};
index
=
{};
index
.
reference
=
priv
.
indices
[
i
];
index
.
reference
=
priv
.
indices
[
i
];
index
.
name
=
index
.
reference
[
"
name
"
];
index
.
current
=
indices
[
index
.
reference
.
name
];
index
.
current
=
indices
[
index
.
name
];
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
index
.
current_size
=
priv
.
getObjectSize
(
index
.
current
);
// a lot of loops, not sure this is the fastest way
// a lot of loops, not sure this is the fastest way
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
for
(
j
=
0
;
j
<
index
.
current_size
;
j
+=
1
)
{
for
(
key
in
index
.
current
)
{
for
(
key
in
index
.
current
)
{
if
(
index
.
current
.
hasOwnProperty
(
key
))
{
obj
=
index
.
current
[
key
];
obj
=
index
.
current
[
key
];
for
(
prop
in
obj
)
{
for
(
prop
in
obj
)
{
for
(
k
=
0
;
k
<
unique_docids
.
length
;
k
++
)
{
if
(
obj
.
hasOwnProperty
(
prop
))
{
if
(
obj
[
prop
]
===
unique_docids
[
k
]
)
{
for
(
k
=
0
;
k
<
unique_docids
.
length
;
k
+=
1
)
{
if
(
obj
[
prop
]
===
unique_docids
[
k
])
{
found
=
true
;
found
=
true
;
break
;
break
;
}
}
}
}
if
(
!
found
)
{
if
(
!
found
)
{
unique_docids
.
push
(
obj
[
prop
]
);
unique_docids
.
push
(
obj
[
prop
]
);
unique_count
+=
1
;
unique_count
+=
1
;
}
}
}
}
}
}
}
}
}
}
}
}
// construct allDocs response
// construct allDocs response
all_doc_response
.
total_rows
=
unique_count
;
all_doc_response
.
total_rows
=
unique_count
;
all_doc_response
.
rows
=
[];
all_doc_response
.
rows
=
[];
...
@@ -290,34 +325,15 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -290,34 +325,15 @@ jIO.addStorageType('indexed', function (spec, my) {
priv
.
substorage
,
priv
.
substorage
,
unique_docids
[
m
],
unique_docids
[
m
],
option
,
option
,
function
(
content
)
{
success
,
file
=
{
value
:
{}
};
error
file
.
id
=
unique_docids
[
n
];
file
.
key
=
unique_docids
[
n
];
file
.
doc
=
content
;
all_doc_response
.
rows
.
push
(
file
);
// async counter, must be in callback
n
+=
1
;
if
(
n
===
(
unique_count
))
{
that
.
success
(
all_doc_response
);
}
},
function
(
error
)
{
that
.
error
({
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
error
"
:
"
not_found
"
,
"
message
"
:
"
Cannot find the document
"
,
"
reason
"
:
"
Cannot get a document from substorage
"
});
}
);
);
}
else
{
}
else
{
file
=
{
value
:
{}
};
file
=
{
value
:
{}
};
file
.
id
=
unique_docids
[
m
];
file
.
id
=
unique_docids
[
m
];
file
.
key
=
unique_docids
[
m
];
file
.
key
=
unique_docids
[
m
];
all_doc_response
.
rows
.
push
(
file
);
all_doc_response
.
rows
.
push
(
file
);
if
(
m
===
(
unique_count
-
1
))
{
if
(
m
===
(
unique_count
-
1
))
{
return
all_doc_response
;
return
all_doc_response
;
}
}
}
}
...
@@ -388,7 +404,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -388,7 +404,7 @@ jIO.addStorageType('indexed', function (spec, my) {
"
reason
"
:
"
Document already exists
"
"
reason
"
:
"
Document already exists
"
});
});
return
;
return
;
}
else
{
}
if
(
source
!==
'
PUTATTACHMENT
'
)
{
if
(
source
!==
'
PUTATTACHMENT
'
)
{
indices
=
priv
.
updateIndices
(
indices
,
doc
);
indices
=
priv
.
updateIndices
(
indices
,
doc
);
}
}
...
@@ -428,7 +444,6 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -428,7 +444,6 @@ jIO.addStorageType('indexed', function (spec, my) {
}
}
}
}
);
);
}
};
};
f
.
sendIndices
=
function
(
method
)
{
f
.
sendIndices
=
function
(
method
)
{
indices
.
_id
=
priv
.
index_suffix
;
indices
.
_id
=
priv
.
index_suffix
;
...
@@ -508,7 +523,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -508,7 +523,7 @@ jIO.addStorageType('indexed', function (spec, my) {
function
(
response
)
{
function
(
response
)
{
that
.
success
(
response
);
that
.
success
(
response
);
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -548,7 +563,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -548,7 +563,7 @@ jIO.addStorageType('indexed', function (spec, my) {
function
(
response
)
{
function
(
response
)
{
that
.
success
(
response
);
that
.
success
(
response
);
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
409
,
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
statusText
"
:
"
Conflict
"
,
...
@@ -567,8 +582,8 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -567,8 +582,8 @@ jIO.addStorageType('indexed', function (spec, my) {
option
,
option
,
function
(
response
)
{
function
(
response
)
{
// if deleting an attachment
// if deleting an attachment
if
(
typeof
command
.
getAttachmentId
()
===
'
string
'
){
if
(
typeof
command
.
getAttachmentId
()
===
'
string
'
)
{
f
.
removeDocument
(
'
attachment
'
)
f
.
removeDocument
(
'
attachment
'
)
;
}
else
{
}
else
{
indices
=
priv
.
cleanIndices
(
response
,
doc
);
indices
=
priv
.
cleanIndices
(
response
,
doc
);
// store update index file
// store update index file
...
@@ -588,7 +603,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -588,7 +603,7 @@ jIO.addStorageType('indexed', function (spec, my) {
);
);
}
}
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
@@ -623,7 +638,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -623,7 +638,7 @@ jIO.addStorageType('indexed', function (spec, my) {
// ]
// ]
//}
//}
that
.
allDocs
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
f
=
{},
indices
,
option
,
include_docs
,
all_docs_response
;
var
f
=
{},
option
,
all_docs_response
;
option
=
command
.
cloneOption
();
option
=
command
.
cloneOption
();
if
(
option
.
max_retry
===
0
)
{
if
(
option
.
max_retry
===
0
)
{
option
.
max_retry
=
3
;
option
.
max_retry
=
3
;
...
@@ -644,7 +659,7 @@ jIO.addStorageType('indexed', function (spec, my) {
...
@@ -644,7 +659,7 @@ jIO.addStorageType('indexed', function (spec, my) {
that
.
success
(
all_docs_response
);
that
.
success
(
all_docs_response
);
}
}
},
},
function
(
err
)
{
function
()
{
that
.
error
({
that
.
error
({
"
status
"
:
404
,
"
status
"
:
404
,
"
statusText
"
:
"
Not Found
"
,
"
statusText
"
:
"
Not Found
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment