mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2024-11-22 14:25:01 +01:00
Split database access into RW and RO
The indexer need to be able to write to the database, but the API only needs to read it.
This commit is contained in:
parent
c554404d7f
commit
89621af85d
4
app.py
4
app.py
@ -3,11 +3,11 @@
|
||||
# https://wiki.duraspace.org/display/DSPACE/Solr
|
||||
|
||||
from config import SOLR_CORE
|
||||
from database import database_connection
|
||||
from database import database_connection_ro
|
||||
import falcon
|
||||
from solr import solr_connection
|
||||
|
||||
db = database_connection()
|
||||
db = database_connection_ro()
|
||||
solr = solr_connection()
|
||||
|
||||
class ItemResource:
|
||||
|
@ -1,11 +1,18 @@
|
||||
from config import SQLITE_DB
|
||||
import sqlite3
|
||||
|
||||
def database_connection():
|
||||
def database_connection_rw():
|
||||
connection = sqlite3.connect(SQLITE_DB)
|
||||
# allow iterating over row results by column key
|
||||
connection.row_factory = sqlite3.Row
|
||||
|
||||
return connection
|
||||
|
||||
def database_connection_ro():
|
||||
connection = sqlite3.connect('file:{0}?mode=ro'.format(SQLITE_DB), uri=True)
|
||||
# allow iterating over row results by column key
|
||||
connection.row_factory = sqlite3.Row
|
||||
|
||||
return connection
|
||||
|
||||
# vim: set sw=4 ts=4 expandtab:
|
||||
|
@ -5,7 +5,7 @@
|
||||
# https://wiki.duraspace.org/display/DSPACE/Solr
|
||||
|
||||
from config import SOLR_CORE
|
||||
from database import database_connection
|
||||
from database import database_connection_rw
|
||||
from solr import solr_connection
|
||||
|
||||
def index_views():
|
||||
@ -90,7 +90,7 @@ def index_downloads():
|
||||
|
||||
results_current_page += 1
|
||||
|
||||
db = database_connection()
|
||||
db = database_connection_rw()
|
||||
solr = solr_connection()
|
||||
|
||||
# use separate views and downloads tables so we can REPLACE INTO carelessly (ie, item may have views but no downloads)
|
||||
|
Loading…
Reference in New Issue
Block a user