Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82357688
cache.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
Tue, Sep 10, 23:15
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Sep 12, 23:15 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20688511
Attached To
R3600 invenio-infoscience
cache.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
flask
import
current_app
from
invenio.ext.script
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.intbitset
import
intbitset
from
invenio.bibsched
import
server_pid
,
pidfile
from
invenio.ext.sqlalchemy
import
db
from
invenio.modules.record_editor.models
import
Bibrec
from
invenio.modules.formatter.models
import
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
current_app
.
config
.
get
(
'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.legacy.bibfield.bibfield_manager
import
reset
reset
(
split_by
)
@manager.command
@change_command_name
def
reset_recstruct
(
split_by
=
1000
):
"""Reset record structure cache."""
from
invenio.legacy.bibrecord.bibrecord_manager
import
reset
reset
(
split_by
)
def
main
():
from
invenio.base.factory
import
create_app
app
=
create_app
()
manager
.
app
=
app
manager
.
run
()
if
__name__
==
'__main__'
:
main
()
Event Timeline
Log In to Comment