Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F76512809
cache_manager.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Aug 8, 09:36
Size
3 KB
Mime Type
text/x-python
Expires
Sat, Aug 10, 09:36 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19725953
Attached To
R3600 invenio-infoscience
cache_manager.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
from
invenio.scriptutils
import
Manager
,
change_command_name
manager
=
Manager
(
usage
=
"Perform cache operations"
)
def
reset_rec_cache
(
output_format
,
get_record
,
split_by
=
1000
):
"""It either stores or does not store the output_format.
If CFG_BIBUPLOAD_SERIALIZE_RECORD_STRUCTURE is changed, this function
will adapt the database to either store or not store the output_format."""
import
sys
try
:
import
cPickle
as
pickle
except
:
import
pickle
from
itertools
import
islice
from
invenio.config
import
CFG_BIBUPLOAD_SERIALIZE_RECORD_STRUCTURE
from
invenio.intbitset
import
intbitset
from
invenio.bibsched
import
server_pid
,
pidfile
from
invenio.sqlalchemyutils
import
db
from
invenio.bibedit_model
import
Bibrec
,
Bibfmt
pid
=
server_pid
(
ping_the_process
=
False
)
if
pid
:
print
>>
sys
.
stderr
,
"ERROR: bibsched seems to run with pid
%d
, according to
%s
."
%
(
pid
,
pidfile
)
print
>>
sys
.
stderr
,
" Please stop bibsched before running this procedure."
sys
.
exit
(
1
)
if
CFG_BIBUPLOAD_SERIALIZE_RECORD_STRUCTURE
:
print
">>> Searching records which need
%s
cache resetting; this may take a while..."
%
(
output_format
,
)
all_recids
=
intbitset
(
db
.
session
.
query
(
Bibrec
.
id
)
.
all
())
#TODO: prevent doing all records?
recids
=
all_recids
print
">>> Generating
%s
cache..."
%
(
output_format
,
)
tot
=
len
(
recids
)
count
=
0
it
=
iter
(
recids
)
while
True
:
rec_group
=
tuple
(
islice
(
it
,
split_by
))
if
not
len
(
rec_group
):
break
Bibfmt
.
query
.
filter
(
db
.
and_
(
Bibfmt
.
id_bibrec
.
in_
(
rec_group
),
Bibfmt
.
format
==
output_format
))
.
delete
(
synchronize_session
=
False
)
db
.
session
.
commit
()
#TODO: Update the cache or wait for the first access
map
(
get_record
,
rec_group
)
count
+=
len
(
rec_group
)
print
" ... done records
%s
/
%s
"
%
(
count
,
tot
)
if
len
(
rec_group
)
<
split_by
or
count
>=
tot
:
break
print
">>>
%s
cache generated successfully."
%
(
output_format
,
)
else
:
print
">>> Cleaning
%s
cache..."
%
(
output_format
,
)
Bibfmt
.
query
.
filter
(
Bibfmt
.
format
==
output_format
)
.
delete
(
synchronize_session
=
False
)
db
.
session
.
commit
()
@manager.command
@change_command_name
def
reset_recjson
(
split_by
=
1000
):
"""Reset record json structure cache."""
from
invenio.bibfield_manager
import
reset
reset
(
split_by
)
@manager.command
@change_command_name
def
reset_recstruct
(
split_by
=
1000
):
"""Reset record structure cache."""
from
invenio.bibrecord_manager
import
reset
reset
(
split_by
)
def
main
():
from
invenio.webinterface_handler_flask
import
create_invenio_flask_app
app
=
create_invenio_flask_app
()
manager
.
app
=
app
manager
.
run
()
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment